You are not logged in.

#1 08 Feb 2017 11:27

jb7731
Member
Registered: 08 Feb 2017
Posts: 5

SSH -> cmd /c -> capture console output

Hi everyone

I am trying to call a module (for example python or vbs) on a Windows client ( Microsoft Windows [Version 6.1.7601] with Win32-OpenSSH ) from a Linux Server over ssh.
The module is very simple only containing a print command (for example "Hello World")

This is what I got so far:

A)
ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c python.exe test.py
ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c cscript test.vbs
...
-> no print output returned

B)
ssh CONNECT-STRING(-i, domain, username, host) python.exe test.py
ssh CONNECT-STRING(-i, domain, username, host) cscript test.vbs
-> print output returned

Unfortunately i need to use the implementation A) because our job-server script executor is defined this way (using cmd.exe /c).

Maybe somebody could give me a explanation why the first implementation does not return the print output.
Is there any kind of way in order to return the output?

Please excuse my english.

Thank you very much for your help.

Cheers jb

Offline

#2 08 Feb 2017 13:31

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: SSH -> cmd /c -> capture console output

Possibly your remote session is not picking up the system PATH

Try giving the full path to CMD.exe e.g. C:\Windows\System32\cmd.exe

Offline

#3 08 Feb 2017 14:08

jb7731
Member
Registered: 08 Feb 2017
Posts: 5

Re: SSH -> cmd /c -> capture console output

Hi,

I tried it with the full path and it didnt work either.

In the meantime I did find an acceptable workaround that I can use in our Job-Server by type to the invokation string of the job:

python.exe ${scriptfile} && type {templogfile}

By using an unique templogfile which used in the job and typed then after the script ends.

Unfortunately I still dont know exactly why my initial implementation did not work.

Neverthelesse thank you very much for your input.

Cheers

Offline

#4 08 Feb 2017 14:21

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: SSH -> cmd /c -> capture console output

Offline

#5 09 Feb 2017 08:59

jb7731
Member
Registered: 08 Feb 2017
Posts: 5

Re: SSH -> cmd /c -> capture console output

We are using Windows 7 (32 bit). Reason is we have some applications that are still requiring 32 bit.

Offline

#6 09 Feb 2017 10:35

jb7731
Member
Registered: 08 Feb 2017
Posts: 5

Re: SSH -> cmd /c -> capture console output

I was able to do some further tests:

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c ipconfig
-> no output

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c systeminfo
-> no output

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c driverquery
-> no output

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c driverquery
-> no output

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c tasklist
-> no output



ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c date
-> working

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /c vol
-> working

Offline

#7 09 Feb 2017 11:12

jb7731
Member
Registered: 08 Feb 2017
Posts: 5

Re: SSH -> cmd /c -> capture console output

..and

ssh CONNECT-STRING(-i, domain, username, host) cmd.exe  ipconfig or
ssh CONNECT-STRING(-i, domain, username, host) cmd.exe /k  ipconfig

returns the following error message (german):
Für diesen Befehl ist nicht genügend Speicher verfügbar

Translated:
Not enough storage is available to process this command


I think that resolving this problem could solve my cmd /c problem too.

Offline

#8 16 Feb 2017 13:19

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: SSH -> cmd /c -> capture console output

I think your latest error is a red herring.

From the commands you mentioned, the common factor would appear to be that running built-in commands (date, vol) works, whereas binaries doesn't (would need more information to understand why that might be).

You could maybe try using this, to use a built-in to start the binary:

cmd /c start /b "" ipconfig

The empty set of double quotes is not a typo.

You could also try redirecting STDERR to STDOUT (in case your connection method is only capturing STDOUT and thus masking an error which could point you toward the problem.)  So something like this: 

cmd /c ipconfig 2>&1

Or

cmd /c start /b "" ipconfig 2>&1

It might need some escaping to work correctly.

Last edited by bluesxman (16 Feb 2017 13:26)


cmd | *sh | ruby | chef

Offline

Board footer

Powered by