简体   繁体   English

如何防止PuTTY shell在Windows中从批处理文件执行命令后自动退出?

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

I have written a batch file like this: 我写了一个这样的批处理文件:

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

Then in dummy.text I have written this command: 然后在dummy.text我写了这个命令:

avahi-daemon --no-drop-root -D
export XVHMI_USERCONFIG_PATH=/home/UserProfileConfig
export XDG_RUNTIME_DIR=/tmp
cd /opt/bosch/airis/bin

When I run the .bat file, PuTTY starts, commands execute (hopefully, not sure) and it exits. 当我运行.bat文件时,PuTTY启动,命令执行(希望,不确定)并退出。

How to keep that window open? 如何保持窗口打开?

I have googled for the same, but no solid help. 我用谷歌搜索了同样的,但没有坚实的帮助。 I read on stack overflow itself that we need to define something in txt file, but what and most importantly how? 我读到堆栈溢出本身,我们需要在txt文件中定义一些东西,但是最重要的是什么?

The SSH session closes (and PuTTY with it) as soon as the command finishes. 命令完成后,SSH会话将立即关闭(以及PuTTY)。 Normally the "command" is shell. 通常“命令”是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: 由于你已经覆盖了这个默认的“命令”,但是你想要运行shell,你必须自己明确地执行shell:

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. 另外,由于使用-m开关意味着非交互式终端,您可能希望使用-t开关强制交互式终端。


Though, I'm not really sure if you want to execute shell or if you just want to see your command output. 虽然,我不确定你是否想要执行shell,或者你只是想看看你的命令输出。 If the latter, did you consider using plink ? 如果是后者,你考虑使用plink吗? It's console terminal client from PuTTY package. 它是PuTTY软件包的控制台终端客户端。 Being console application, it inherits console of parent batch file, and you can pause the batch console from closing using pause command, if needed. 作为控制台应用程序,它继承了父批处理文件的控制台,如果需要,您可以使用pause命令暂停批处理控制台的关闭。

Another option (both for PuTTY and plink) is to pause on remote side. 另一个选项(PuTTY和plink)都是在远端暂停。 Eg Using read command. 例如,使用read命令。

avahi-daemon ... ; read

As suggested by Martin I tried this step: 正如马丁所建议我尝试了这一步:

  1. putty.exe -ssh 172.17.0.52 -l root -m dummy.txt -t putty.exe -ssh 172.17.0.52 -l root -m dummy.txt -t

  2. added /bin/bash at the end of commands in dummy.txt 在dummy.txt中的命令末尾添加/ bin / bash

It worked for me. 它对我有用。 Please note, you have to follow both the steps as mentioned above. 请注意,您必须遵循上述两个步骤。 This way you can keep the session alive and can manually execute further commands. 这样,您可以使会话保持活动状态,并可以手动执行其他命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM