How does PUTTY/PLINK determine a command has returned?

南笙酒味 提交于 2019-12-12 01:31:32

问题


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?


回答1:


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.




回答2:


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:

echo 'executing powershell...' | C:\windows\system32\windowspowershell \v1.0\powershell.exe  exit 1

So then your full plink command becomes:

plink.exe user@someIp -i key.ppk -P 22 -batch -v "echo 'executing powershell...' | C:\windows\system32\windowspowershell\v1.0\powershell.exe exit 1"

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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/2975992/how-does-putty-plink-determine-a-command-has-returned

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!