views:

381

answers:

4

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  A: 

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.

Marcus Adams
So would it be a fair assumption to say that powershell is succeeding quietly? How can this be? I even explicitly set return codes, echo prompt, throw exceptions and it still hangs?
jacko
Does it run quickly, perhaps even spawning another process, then die? If not, the shell isn't going to get control back. How are the return codes being returned? Are they being returned to stdout on the server? You should probably put the call in a script that allows you to handle the return code.
Marcus Adams
When I run from the shell (putty), it detects the finish successfully. When I run it via plink, the command still runs but plink hangs waiting for the response?
jacko
A: 

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

jacko
A: 

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.

OblongZebra