Script Assistance w/ system.util.execute()

Hello, I am an intern working in ignition right now on a small project and was wondering if I could get some clarity/assistance with a specific issue I am having. Basically, in this project I have a command that is stored as a string, and I need to open up the command prompt and send it. I know the command works on its own within command prompt and I am also able to open command prompt using system.util.execute(), but for some reason I cannot combine the two. I have tried
system.util.execute(["cmd.exe", "/C", command]) as well as other solutions like ["C:\Windows\System32\cmd.exe", "/C", command] but just cannot get it to work. I think that the script is finding an issue with the command as it first starts off with a file path and then has a "-a" after the file path. I know that the issue starts with the -a as I can get the script to run, open cmd, and then find the file in the file path. The "-a" is what causes it to be unusable. I have tried everything.

For clarity I am running this:
command = "ExampleFilePath" -a "OtherInfo"
system.util.execute(["C:\Windows\System32\cmd.exe", "/C", command])

Thank you!

You need to enclose the entire command string inside single quotes. You may even have to escape the double-quotes, but I would try without escaping them.

For example your example should be like this:

command = '"ExampleFilePath" -a "OtherInfo"'
system.util.execute(["C:\Windows\System32\cmd.exe", "/C", command])

Otherwise without the extra single quotes it isn't reading it as a single string but 2 separate strings separated by a -a which is probably causing your error.

Also, next time, put your code in a preformatted text block to make it look cleaner.

2 Likes