# Access Windows Command Line

**URL:** <https://forum.inductiveautomation.com/t/access-windows-command-line/14720>\
**Category:** Ignition\
**Created:** [July 7, 2017, 5:11pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720 "2017-07-07T17:11:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel.desimone](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@daniel.desimone](https://forum.inductiveautomation.com/u/daniel.desimone)\
**Post date:** [July 7, 2017, 5:11pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/1 "2017-07-07T17:11:13Z")

</div>

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 app.run.execute(string) 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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 7, 2017, 6:31pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/2 "2017-07-07T18:31:34Z")

</div>

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

```auto
system.util.execute(args)

```

---

<div class="post-metadata">

**Author:** ![daniel.desimone](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@daniel.desimone](https://forum.inductiveautomation.com/u/daniel.desimone)\
**Post date:** [July 7, 2017, 8:14pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/3 "2017-07-07T20:14:03Z")

</div>

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

```auto
import system
if system.tag.read('troubleshooting/1_3_6_1_4_1_27358_3_51_0').value == 0:
	value = '1'
else:
	value = '0'
print 'rly 12 to ' + str(value)
args = ['cmd.exe', '/k', 'snmpset', '-v', '2c', '-c', 'private', '192.168.1.33', '.1.3.6.1.4.1.27358.3.51.0', 'i', value]
system.util.execute(args)

```

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 7, 2017, 8:17pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/4 "2017-07-07T20:17:29Z")

</div>

> [@daniel.desimone](#):
>
> .1.3.6.1.4.1.27358.3.51.0

Is the extra '.' at the beginning intentional?

---

<div class="post-metadata">

**Author:** ![daniel.desimone](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@daniel.desimone](https://forum.inductiveautomation.com/u/daniel.desimone)\
**Post date:** [July 7, 2017, 8:25pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/5 "2017-07-07T20:25:54Z")

</div>

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:

```auto
cmd.exe /k snmpset -v 2c -c private 192.168.1.33 .1.3.6.1.4.1.27358.3.51.0 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.

---

<div class="post-metadata">

**Author:** ![daniel.desimone](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@daniel.desimone](https://forum.inductiveautomation.com/u/daniel.desimone)\
**Post date:** [July 7, 2017, 9:16pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/6 "2017-07-07T21:16:44Z")

</div>

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 @paul-griffith for your solution! If anyone knows why it doesn’t work in the designer, I’m all ears.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 7, 2017, 9:16pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/7 "2017-07-07T21:16:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 7, 2017, 9:18pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/8 "2017-07-07T21:18:31Z")

</div>

> [@pturmel](#):
>
> You will need to use system.tag.write()

Heh. Never mind. /-:

---

<div class="post-metadata">

**Author:** ![kevin.deyoung](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.deyoung/32/9558_2.png) [@kevin.deyoung](https://forum.inductiveautomation.com/u/kevin.deyoung)\
**Post date:** [July 12, 2018, 2:40pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/9 "2018-07-12T14:40:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 12, 2018, 2:42pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/10 "2018-07-12T14:42:36Z")

</div>

It’s not possible with the `system.util.execute()` function, but is possible using the Python standard library [`subprocess`](http://www.jython.org/docs/library/subprocess.html) 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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 12, 2018, 2:52pm UTC](https://forum.inductiveautomation.com/t/access-windows-command-line/14720/11 "2018-07-12T14:52:38Z")

</div>

> [@paul-griffith](#):
>
> 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.
