System.util.execute question

When I run system.util.execute([“C:\windows\system32\cmd.exe”,"/C",“start”,“C:\Users\Nick Ruimveld\Documents\Hello.bat”]), this is what is shown:

This is what’s inside the batch file:

echo off
title Hello World!
:: See the title at the top.
echo Test file executed.
echo I am too lazy to write commands again and again.
pause

1 Like

Backslashes need to be escaped with, of all things, a backslash

system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Users\\Nick Ruimveld\\Documents\\Hello.bat"])

Python is also pretty forgiving on paths using forward slashes:

system.util.execute(["C:/windows/system32/cmd.exe","/C","start","C:/Users/Nick Ruimveld/Documents/Hello.bat"])
1 Like

Just curious, how would you deal with files that have space in them?
I know you can put double quotations around the file name if you’re actually in cmd.exe in windows:
C:\users\userName\Desktop\"name name.jpg"
and it works just fine but how would you do that if you are running system.util.execute() in Ignition?
I tried to squeez the double quotation in there but didn’t like it, kept openning
C:\users\userName\Downloads

asking for a friend :grin: :nerd:

You should be able to swap the quotes around, eg use single quotes around the Python character sequence, which will then pass unmodified (including double quotes) to the execute function:
system.util.execute(['cmd.exe', '"C:\Users\username\Desktop\some long file name.jpg"'])

Thanks for the quick reply @PGriffith
I tried your way and it wouldn’t even open the cmd. It doesn’t like the ‘cmd.exe’ by itself, I had to use: 'C:/windows/system32/cmd.exe','/C','start'
for it to even do anything and even after that still opens:
C:\users\userName\Downloads (when done in designer)
and
C:\windows\system32 (when done in client)
Even if I only point the path to Desktop but the moment i take away either the double quotes or single quotes it opens the Desktop just fine.
Any other suggestions?

Close :slight_smile:

Here’s one that worked for me.

system.util.execute(['cmd.exe', '/C', 'C:/Users/username/Desktop/some long file name.jpg'])

No double quotes should be needed.

EDIT: If you are trying to open a file, then ‘start’ shouldn’t be needed, either.

2 Likes

Thanks @JordanCClark :+1: