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

run powershell commands using system.callSystem()

Engaged ,
Apr 23, 2019 Apr 23, 2019

Copy link to clipboard

Copied

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

Views

3.0K

Translate

Translate

Report

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

...

Votes

Translate

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

Copy link to clipboard

Copied

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'});

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

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