开发者

How does PUTTY/PLINK determine a command has returned?

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 comm开发者_运维技巧and hangs...

Any ideas?


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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜