weird whitespace problem getting data out of cmd.run nssm on Windows

407 views
Skip to first unread message

Barry Laffoy

unread,
Feb 27, 2015, 9:26:45 AM2/27/15
to salt-...@googlegroups.com
Hi

I'm trying to build a simple state module around nssm, but I'm running into a problem where any output on stdout gets interpolated with lots of whitespace.

For a service named "myService" running an executable "myService.exe" installed in a python virtualenv at "C:\env\service", I see the following when running a query through Salt

PS C:\Users\blaffoy> salt-call cmd.run "C:\\env\\service\\Scripts\\nssm.exe get myService application"
[INFO    ] Executing command 'C:\\\\env\\\\service\\\\Scripts\\\\nssm.exe get myService application' in directory 'C:\\Users\\blaffoy'
 INFO    ] output: / e n v / s e r v i c e / S c r i p t s / m y S e r v i c e . e x e

local:
    / e n v / s e r v i c e / S c r i p t s / m y S e r v i c e . e x e

Where I expect to see output as I get on the command line:

PS C:\Users\blaffoy> C:\env\service\Scripts\nssm.exe get myService application
/env/service/Scripts/myService.exe

Does anybody have any ideas about why this might be happening?

Other command line output from Windows on Salt looks normal. I tried setting the shell=powershell and shell=cmd, but from looking the salt/modules/cmdmod.py, I don't think this has any effect in Windows. Also, if I make a call to this same command line in a Python shell using subprocess.Popen, the output appears correct. From reading salt/utils/timed_subprocess.py, Salt uses subprocess.Popen to implement cmd.run. I don't see anywhere in the call chain where the values might be modified.

I'm running different versions for the salt-minion and salt-master. Could this be the source of the problem? Unfortunately, I'm tied to an older version of salt on Windows due to the bug outlined here (https://github.com/saltstack/salt/issues/8405), but I make use of some of the newer features of salt on Ubuntu machines.

Versions Reports:
Minion:
PS C:\Users\blaffoy-admin> salt-call.exe --versions-report
           Salt: 2014.1.13
         Python: 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
         Jinja2: 2.7.1
       M2Crypto: 0.21.1
 msgpack-python: 0.4.2
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.11
          PyZMQ: 14.1.1
            ZMQ: 4.0.4

Master:
blaffoy@lon-cfp-dev-002:~$ salt-call  --versions-report
           Salt: 2014.7.1
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.3
       M2Crypto: 0.22
 msgpack-python: 0.4.5
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.11
          ioflo: Not Installed
          PyZMQ: 14.4.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: 0.9.1


Any input appreciated
Barry

Barry Laffoy

unread,
Feb 27, 2015, 9:35:42 AM2/27/15
to salt-...@googlegroups.com
Actually, I just tried running this command remotely from the master, and the output looks okay:

blaffoy@master:~$ sudo salt minion cmd.run "/env/service/Scripts/nssm.exe get myService application"
minion.cfpartners.local:
    /env/service/Scripts/myService.exe

Now I'm even more confused.

Barry Laffoy

unread,
Feb 27, 2015, 11:19:18 AM2/27/15
to salt-...@googlegroups.com
On closer inverstigation, it's not whitespace: every char in the returned strings have been wrapped in ascii null characters.


On Friday, 27 February 2015 14:26:45 UTC, Barry Laffoy wrote:

David Boucha

unread,
Feb 27, 2015, 2:53:08 PM2/27/15
to salt users list
I haven't seen this issue before. Do you think it's nssm that's returning some extra data or Salt?

If you think it's Salt specific, could you open an issue on Github for this? That way we won't lose track of it.

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Barry Laffoy

unread,
Mar 2, 2015, 10:17:28 AM3/2/15
to salt-...@googlegroups.com
Okay, after a bit more work, I've seen similar behaviour coming from nssm straight from the command line when called in a remote powershell session. That makes me pretty sure that this isn't a Salt problem. Whether that makes it a Powershell, WinRM, or nssm problem isn't clear right now, but it's not appropriate for this list either way.

Cheers for the feedback anyway.

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/DTstUL3qHzk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Peder Schmedling

unread,
Feb 9, 2016, 1:28:07 PM2/9/16
to Salt-users
Did you get to the bottom of this?
I'm experiencing the same using just Powershell and nssm, trying to capture the output from several calls to nssm form powershell.

best regards
Peder 

Barry Laffoy

unread,
Feb 10, 2016, 5:50:10 AM2/10/16
to salt-...@googlegroups.com
Sorry, I stopped working on this almost a year ago. I don't remember exactly what the outcome was, but I'm pretty sure I never solved the problem.

Peder Schmedling

unread,
Feb 10, 2016, 9:29:44 AM2/10/16
to Salt-users
For future reference if anyone should stumble onto this thread (as I did):

I solved my issue in powershell by issuing this command before capturing console output from nssm:
[Console]::OutputEncoding = [System.Text.Encoding]::Unicode

Peder

Barry Laffoy

unread,
Feb 10, 2016, 9:33:01 AM2/10/16
to salt-...@googlegroups.com
Oh, well done. I did not think of that.
Reply all
Reply to author
Forward
0 new messages