Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 712
user634056 Avatar asked Dec 10 '25 20:12

user634056


2 Answers

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.....

like image 199
EMI Avatar answered Dec 13 '25 05:12

EMI


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!

like image 44
Devnull Avatar answered Dec 13 '25 07:12

Devnull