bash plink 不会返回到命令提示符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21456402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
plink won't return to command prompt
提问by user3252141
I try to execute a bash script via plink. Script looks something like this:
我尝试通过 plink 执行 bash 脚本。脚本如下所示:
echo "@ Starting process..."
./bin/process "process.cfg" &
disown %1
echo "@ Done!"
When i execute this script in a terminal on linux, everything works fine. After the "Done!" line I get a command prompt (as expected).
当我在 linux 上的终端中执行此脚本时,一切正常。在“完成!”之后 行我得到一个命令提示符(如预期的那样)。
Now when I run this script via plink, the output stops afyer the "Done!" line, but plink won't return to the command prompt and "hangs" until +c.
现在,当我通过 plink 运行此脚本时,输出会在“完成!”之后停止。行,但 plink 不会返回到命令提示符并“挂起”直到 +c。
The script is placed in a file and given to plink with the -m parameter
脚本被放置在一个文件中,并使用 -m 参数给出 plink
I tried addind 'logout', 'exit', 'set -e' at the end of the script, but it doesn't help. Also adding -batch, -T or -N to the plink command brought no success.
我尝试在脚本末尾添加 'logout'、'exit'、'set -e',但没有帮助。在 plink 命令中添加 -batch、-T 或 -N 也没有成功。
Any ideas on how to fix this?
有想法该怎么解决这个吗?
回答by user3252141
Ok, it seems I had to detach stdout/err from the terminal. In a normal terminal this wouldn't matter ofcourse, but plink remained in a "busy" state because of this.
好的,看来我必须从终端上分离 stdout/err。在普通终端中,这当然无关紧要,但因此 plink 仍处于“忙碌”状态。
So, inside my bash script (which executed the command) I had to change:
因此,在我的 bash 脚本(执行命令)中,我必须更改:
./bin/process "process.cfg" &
./bin/process "process.cfg" &
to:
到:
./bin/process "process.cfg" /dev/null 2>&1 &
./bin/process "process.cfg" /dev/null 2>&1 &
plink now returns the correct "finished" state at the end of the bash script.
plink 现在在 bash 脚本的末尾返回正确的“完成”状态。
回答by Zahra
plink.exe -P PORT_NUM -v USERNAME@HOST_IP -pw PASSWD "COMMAND >/dev/null &"
plink.exe -P PORT_NUM -v USERNAME@HOST_IP -pw PASSWD "COMMAND >/dev/null &"
&
would move your process to the background> /dev/null
allows your command run silently by getting stdout/stderr to output to a dummy null device
&
会将您的流程移至后台> /dev/null
通过让 stdout/stderr 输出到虚拟空设备,允许您的命令静默运行
note: the shell command is wrapped in "double quotations"
注意:shell 命令用“双引号”括起来
回答by Cyrille
Plink has a -batch
parameter which disable all interactive prompts. It may be what you need here to avoid hanging until ctrl-C.
Plink 有一个-batch
禁用所有交互式提示的参数。这可能是您在此处避免挂起直到 ctrl-C 所需要的。