Access Windows Command Line

I need to pipe a string into the windows command line and run it. Specifically, I need to run ‘snmpset -v 2c -c private XXX.XXX.XXX.XXX #.#.#.oid.#.#.# i 1’, so an SNMP set command using net-snmp. That’s all working fine from the windows command line, I just need to get the command there from ignition.

Normally I would use the os.popen() method, but since this is jython that gets me into java instead of windows.

In other forum posts, I see people using or similar things, but when I attempt to use these in ignition, the app library doesn’t have a run option or any of the other options I’ve seen in the forum. The closest I’ve gotten is system.util.execute, but since I’m not running and executable file this doesn’t work.

You might be able to use system.util.execute and cmd.exe like this:


You know, it seems like this would work, but it doesn’t. Here’s what I wrote, fired off a button:

import system
if'troubleshooting/1_3_6_1_4_1_27358_3_51_0').value == 0:
	value = '1'
	value = '0'
print 'rly 12 to ' + str(value)
args = ['cmd.exe', '/k', 'snmpset', '-v', '2c', '-c', 'private', '', '.', 'i', value]

Everything runs without any errors, but my SNMP target never sets.

Is the extra '.' at the beginning intentional?

Yes that’s supposed to be there. I know it looks funny. For the record, this code when put in a console runs just fine:

cmd.exe /k snmpset -v 2c -c private . i 0

I made that by pasting the args list into the console, deleting the quotes and commas, and replacing value with 0. It ran and sucessfully wrote a 0 to the target.

So UPDATE: turns out this does work! Not sure why, but it only works after I save the page and run the script from the client instead of using the preview mode in the designer. Thanks @PGriffith for your solution! If anyone knows why it doesn’t work in the designer, I’m all ears.

You will need to use system.tag.write() to set your tag. ‘value’ is just a local jython variable as shown.

Heh. Never mind. /-:

OK, so I’m a newbie to Ignition and also need to issue Windows command lines. However, I’d also like to get the status back from the command that is issued. Is that possible?

It’s not possible with the system.util.execute() function, but is possible using the Python standard library subprocess module. Note that you should be careful running this from the event dispatch thread (ie, directly within a client) as a long running command could lock up the interface.


s/be careful running/never run/

Really, never run a subprocess from an event.

1 Like