Reputation: 51
I have a Powershell .ps script which does some elementary stuff in a windows machine. I invoke this script by ssh-ing to the windows machine. The Windows machine has cygwin Open-SSh installed on it.
Problem : the script gets executed but doesn't return back to the SSH session. How do I get the powershell script to end and return control back to SSH session?
Upvotes: 3
Views: 4938
Reputation: 125
Devnull's solution worked for me, but the key was the <NUL
.
I was trying to execute a Powershell command over a Cygwin Openssh connection from a Perl script on a remote machine. Instead of creating a batch file, I write the Powershell commands to a ps1 file, transfer this via scp, and then execute it over ssh with the following Perl:
my ($stdout,$stderr) = Net::SSH->new( "user@host" )->capture2( { timeout => $timeout }, "powershell -file $copied_ps1_file<NUL");
Upvotes: 0
Reputation: 21
Might be a bit late to answer, but we had a similar problem after installing cygwin sshd to run powershell commands on a citrix server from a linux webserver.
We ended up falling on this page: http://epeleg.blogspot.com/2010/06/solution-to-powershell-never-exists.html
Which prompted us to create a batch file with the powershell command inside of it, and the following syntax:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -Command "& { "your powershell script and arguments here" }"<NUL
We just run the batch file instead of calling powershell directly, and use %1 as a variable if we need one in the batch file.
the <NUL at the end tells powershell not to expect input, and makes it quit back to the ssh prompt. I hope this helps you, or someone falling on this thread!
Upvotes: 2