How to prevent PuTTY shell from auto-exit after executing command from batch file in Windows?

前端 未结 2 1206
清歌不尽
清歌不尽 2021-01-04 06:15

I have written a batch file like this:

Start putty.exe -ssh 172.17.0.52 -l root -m dummy.txt

The

2条回答
  •  北海茫月
    2021-01-04 06:53

    The SSH session closes (and PuTTY with it) as soon as the command finishes. Normally the "command" is shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:

    avahi-daemon ... ; /bin/bash
    

    Also as use of -m switch implies a non-interactive terminal, you probably want to force an interactive terminal back using -t switch.


    Though, I'm not really sure if you want to execute shell or if you just want to see your command output. If the latter, did you consider using plink? It's console terminal client from PuTTY package. Being console application, it inherits console of parent batch file, and you can pause the batch console from closing using pause command, if needed.

    Another option (both for PuTTY and plink) is to pause on remote side. E.g. Using read command.

    avahi-daemon ... ; read
    

提交回复
热议问题