How does studio.system.start work?

I want to run a .exe through a custom command and pass in some args. When trying:

studio.system.start("absolute path to the .exe", {timeout: 1000})
It throws:
Process failed to start: The system cannot find the file specified. (ErrorCode: 0)

studio.system.start({workingDir: "absolute or relative path to the .exe"}, {timeout: 1000})
same thing

studio.system.start("relative path to the .exe from working dir", {timeout: 1000, workingDir: "c:"})

same thing

studio.system.start("C:/Windows/System32/cmd.exe", {})
→ Process operation time out (ErrorCode: 2)

Hi,

For your first example, it’s likely that something about your path is causing it to fail. Unfortunately, without seeing the path, I can’t comment on what that is. For example, the following works fine for me:

studio.system.start("C:/Users/MyUsername/AppData/Local/Programs/Microsoft VS Code/Code.exe", {timeout: 1000})

For your second and third examples, workingDir is the directory that the new process/executable will be opened in, not the path from which your pathToExecutable argument operates from. In your second example, you haven’t provided a path to your executable (and timeout should be in {}). In your third example, if your relative path is from the FMOD Studio executable, and not workingdir, it should be fine - my FMOD Studio install directory is:

"C:/Program Files/FMOD SoundSystem/FMOD Studio 2.0x.xx"

so the following command that uses a relative path works:

studio.system.start("../../../Users/MyUsername/AppData/Local/Programs/Microsoft VS Code/Code.exe", {timeout: 1000, workingDir: "C:/"})

If the above hasn’t cleared up your confusion, and/or your paths still don’t work, could I get you to provide your FMOD Studio version?

As for directly running cmd, I have been able to reproduce an issue with it not opening a window, and hanging for a long time when attempting to do so, and I’ve noted this in our internal issue tracker. However, If you specify “/c” in your args, cmd will still execute commands and then terminate. For example, you can indirectly open a cmd window with studio.system.start("cmd", {args: "/c start cmd"}), and the following should write “blahblahblah” to “textFile.txt” in your local user folder (i.e. “C:/Users/YourUsername”):

studio.system.start("cmd.exe", {args: "/c echo blahblahblah >> %UserProfile%/testFile.txt"})

Bit of an info dump, but I hope it helps.

Hi @Leah_FMOD , thanks for the info! Turned out it was a permission issue, after I change the batch script’s output path everything starts working. (Also the cmd workaround is great to know, thx!) I do want to submit a bug on a not related script API call in case other people run into it as well (or maybe it just happens to me locally).

I was trying to make a shortcut for reloading Studio API scripts, doing the following call either from the script or directly typing into the console crashes the Studio Editor.
studio.window.triggerAction(studio.window.actions.ScriptReload)

No problem, it’s good to hear you’ve resolved the issue.

That’s a known bug, and studio.window.actions.ScriptReload has been disabled as of 2.02.13 as a result. Unfortunately there’s no workaround that I can find to directly reload scripts via the Studio Scripting API. However, if you’re just trying to set a keyboard shortcut, you can do so in Edit → Preferences → Shortcuts → Scripts: Reload.

1 Like