user634056
user634056

Reputation: 51

How to end s Powershell script when running from cygwin

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

Answers (3)

Chinthamani
Chinthamani

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

EMI
EMI

Reputation: 826

Nice and simple solution here:

https://serverfault.com/questions/266535/how-to-run-a-powershell-script-from-cygwin-ssh-session#comment277301_266699

echo "\n" | powershell ....etc.....

Upvotes: 4

Devnull
Devnull

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

Related Questions