PUTTY/PLINK 如何确定命令已返回?
是换行吗?迅速的?到底是什么?
尝试通过 plink 运行 powershell 并且命令执行,但 plink 无法识别其已完成并且会话挂起。最奇怪的是,该命令在通过 shell(通过 Putty)发送时成功执行。但是,当通过 plink 发送时,相同的命令会挂起......
有什么想法吗?
Is it newline? prompt? What exactly?
Trying to run powershell over plink and the command executes but plink doesn't recognise its finished and the session hangs. Most curiously though, the command executes successfully when sent through the shell (via Putty). However, when sent via plink, the same command hangs...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Telnet 几乎是一个原始的 TCP 连接。 Putty 需要返回的只是服务器的响应。其余的由 shell 和 SSH/Telnet 服务器控制。
当您的任务运行时,它不会返回命令提示符。
在 Linux、Unix 和 Mac OS X 上,您可以在命令后面添加
&
以在后台运行它并返回到命令提示符。尝试在本地终端/命令 shell 中运行它。您基本上应该看到相同的事情。
Telnet is nearly a raw TCP connection. All Putty needs back is a response from the server. The rest is controlled by the shell and SSH/Telnet server.
While your task is running, it's not going to return a command prompt.
On Linux, Unix, and Mac OS X you could put a
&
after the command to run it in the background and return to the command prompt.Try running it in the local terminal/command shell. You should basically see the same thing.
好吧,我仍然不太确定问题是什么,但我通过 TeamCity 论坛找到了解决方法。
基本上,您想要回显一些任意字符串并将其输出通过管道传输到您的 powershell 可执行文件中,如下所示:
那么您的完整 plink 命令将变为:
Nb。 Plink 仍将使用此方法传递返回代码和控制台输出。
TeamCity 论坛链接:
http://youtrack.jetbrains.net/issue/TW-6021
希望这有帮助
Ok, well I'm still not quite sure what the problem is, but I've found a workaround via the TeamCity forums.
Basically you want to echo some abitrary string and pipe that output into your powershell executable, like thus:
So then your full plink command becomes:
Nb. Plink will still pass through return codes and console output using this method.
Link to TeamCity forum:
http://youtrack.jetbrains.net/issue/TW-6021
Hope this helps
我在另一个程序中遇到了同样的问题。我在最后一个命令后使用了 >&2 (将输出重定向到 std err),这对我来说效果很好。
I had the same problem with an other program. I used the >&2 (redirect output to std err) after the last command, this worked fine for me.
只需将“return XX”添加到远程shell脚本中,它将返回值到本地控制台。 plink 完成后,输入
echo %errorlevel%
查看返回代码 XX。Just add "return XX" into remote shell script, it will be return value to local console. After plink has been finished, type
echo %errorlevel%
to see return code XX.