Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

run powershell commands using system.callSystem()

Engaged ,
Apr 23, 2019 Apr 23, 2019

Has anyone been able to invoke powershell commands using system.callSystem()?

Here's what I've tried

var response = system.callSystem("powershell.exe /command \"& { gci }\"");
alert(response);

if I try the command from cmd or the windows-r run command thingy I get a directory listing—as expected, but from extendscript I get nothing. I've tried all sorts of variations. Or is cmd the only shell that can be run from system.callSystem()?

TOPICS
Scripting
3.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 15, 2019 Aug 15, 2019

No amount of quoting, escaping or putting inside of braces and brackets will convince powershell to run from callSystem() for me.

What does work is calling cmd, then making powershell the command that cmd runs. Kludgy, but then what did I expect?

e.g.:

system.callSystem("cmd.exe /c powershell.exe -c \"doSome-Powershell -magic $here\"");

You can't return a value from the powershell command though, you have to save the output to a temporary file and read that in the script.

Here's a real example that c

...
Translate
Community Expert ,
Apr 24, 2019 Apr 24, 2019

Strange, I'm seeing the same issue... Are you using a CEP Panel by chance? If so you can achieve this with:

var execSync = require('child_process').execSync;

execSync("powershell.exe /command \"& { gci }\"", {encoding:'UTF-8'});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 15, 2019 Aug 15, 2019

no, just scriptUI. I can't get CEP panels to work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 15, 2019 Aug 15, 2019

No amount of quoting, escaping or putting inside of braces and brackets will convince powershell to run from callSystem() for me.

What does work is calling cmd, then making powershell the command that cmd runs. Kludgy, but then what did I expect?

e.g.:

system.callSystem("cmd.exe /c powershell.exe -c \"doSome-Powershell -magic $here\"");

You can't return a value from the powershell command though, you have to save the output to a temporary file and read that in the script.

Here's a real example that collects all the available system fonts (because Adobe haven't seen fit to make this available to scripters in AE like it is in Photoshop or Illustrator):

system.callSystem("cmd.exe /c powershell.exe -c \"[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing');set-content fontlist.json (convertTo-json(New-Object System.Drawing.Text.InstalledFontCollection))\"");

That saves a file called fontlist.json to the folder where the script is run from. You then have to parse it in extendscript to get the available fonts.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 17, 2019 Aug 17, 2019
LATEST

What kind of font data do you need? If it's just the list of font names, you can do this just in ExtendScript:

var fontFolder = new Folder('C:\\WINDOWS\\Fonts');

var fonts = fontFolder.getFiles();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines