0

I'm trying to undertand if/how I can open an external program from After Effects by using extendscript to send a command through the cmd line (system.callSystem), but can't work it out...

For example, to open a version of Premiere Pro from command line I can use the direct path:

cd C:\Program Files\Adobe\Adobe Premiere Pro CC 2019\ && "Adobe Premiere Pro.exe"

but can't get paths to be read through extendscript, eg I tried:

system.callSystem("cmd.exe /c \"cd C:\Program Files\Adobe\Adobe Premiere Pro CC 2019\ && "Adobe Premiere Pro.exe"\"");

How do I send cmd line commands like this through extendscript? Any help appreciated.

Dan
  • 229
  • 2
  • 6
  • I first recommend to open a [command prompt](https://www.howtogeek.com/235101/), run `cmd /?` and read the output help explaining how the arguments after option `/C` are interpreted by `cmd.exe` and further on last page why a file/folder path containing a space or one of these characters ``&()[]{}^=;!'+,`~`` must be enclosed in double quotes. Well, help of command __CD__ output on running `cd /?` explains that the command __CD__ interprets a space outside a double quoted argument string not as argument separator. But there is additionally used the operator `&&` which is epxlained in detail – Mofi Aug 03 '20 at 05:25
  • in my answer on [Single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564). Therefore I suggest to use as command line to execute by Windows command processor `cd /D "%ProgramFiles%\Adobe\Adobe Premiere Pro CC 2019" && "Adobe Premiere Pro.exe"` or use just `"%ProgramFiles%\Adobe\Adobe Premiere Pro CC 2019\Adobe Premiere Pro.exe"` because I am quite sure that __Adobe Premiere Pro__ can be started with current directory being a different directory than the directory containing the executable. – Mofi Aug 03 '20 at 05:43
  • I don't know nothing about __ExtendScript__, but usually the `system` function in scripts results in executing on Windows in background `%ComSpec% /c` and the specified command with the argument(s) appended. So there is already executed `C:\Windows\System32\cmd.exe /c` and therefore the command line to execute should not contain itself one more `cmd.exe /c` which requires that the used command line is written to be parsed twice by two Windows command processor instances which is most likely one reason for your problem starting __Adobe Premiere Pro__. – Mofi Aug 03 '20 at 05:44
  • Try in __ExtendScript__ the line `system.callSystem("\"%ProgramFiles%\\Adobe\\Adobe Premiere Pro CC 2019\\Adobe Premiere Pro.exe\"");` and see what happens. I am quite sure that your __ExtendScript__ line is syntactically wrong without knowing anything about this scripting language because of not escaping a backslash with one more backslash and because of `"\""` at end of the argument string passed to function `callSystem` and `"` inside the string not escaped with a backslash to be interpreted as literal character and not end of the argument string. – Mofi Aug 03 '20 at 05:45
  • Thanks for the pointers @Mofi, I tried that `system.callSystem("\"%ProgramFiles%\\Adobe\\Adobe Premiere Pro CC 2019\\Adobe Premiere Pro.exe\"");` and After Effects gives an 'Error: The system cannot find the file specified'... still learning so will have to do some more reading on cmd arguments. – Dan Aug 03 '20 at 05:49
  • If `%ProgramFiles%` does not work because of started is 32-bit `C:\Windows\SysWOW64\cmd.exe` instead of 64-bit `C:\Windows\Systerm32\cmd.exe` resulting in expanding `%ProgramFiles%` to `C:\Program Files (x86)` according to Microsoft documentation about [WOW64 Implementation Details](https://learn.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details), I suggest to use either `%ProgramW6432%` or simply the real directory path `C:\\Program Files` instead of an environment variable reference in __ExtendScript__ line. – Mofi Aug 03 '20 at 05:53
  • If it's any help this is the only example I've seen `var timeStr = system.callSystem("cmd.exe /c \"time /t\""); alert("Current time is " + timeStr);` – Dan Aug 03 '20 at 05:58
  • 1
    I suggest to try `system.callSystem("\"C:\\Program Files\\Adobe\\Adobe Premiere Pro CC 2019\\Adobe Premiere Pro.exe\"");`. If that results still in the error message that the file could not be found, try next `system.callSystem("C:\\Program Files\\Adobe\\Adobe Premiere Pro CC 2019\\Adobe Premiere Pro.exe");` without the additional double quotes in case of function `system.callSystem` adds the double quotes by itself in background. That should be documented in the documentation of function `system.callSystem` in __ExtendScript__ documentation which I have not read. – Mofi Aug 03 '20 at 06:04
  • Yes! Thank you! `system.callSystem("\"C:\\Program Files\\Adobe\\Adobe Premiere Pro CC 2019\\Adobe Premiere Pro.exe\"");` worked! The documentation only says "Description: Executes a system command, as if you had typed it on the operating system’s command line. Returns whatever the system outputs in response to the command, if anything. In Windows, you can invoke commands using the /c switch for the cmd.exe command, passing the command to run in escaped quotes (\"...\"). – Dan Aug 03 '20 at 06:09
  • Now I just need to learn how to stop it crashing After Effects as well, haha. Thank you again. – Dan Aug 03 '20 at 06:10

1 Answers1

0

I'm not sure if I fully understand your question. From Extend Script you can make a .BAT file with any commands within and execute it. Here is the example how you can open Notepad:

function run(cmd) {
    var f = new File(Folder.temp.fsName + "/temp.bat");
        f.open("w");
        f.writeln(cmd);
        f.close();
        f.execute();
}

run("c:/Windows/notepad.exe");
Dharman
  • 30,962
  • 25
  • 85
  • 135
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23