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

Question about executing python files with node.js "child_process"

New Here ,
Oct 31, 2019 Oct 31, 2019

Hello!
I am trying to execute a python file in my PP extention, i read that 'node.js' and 'child_process' is the way to go if you want to run CLI commands in javascript, so i went to my XML file and enabled it ( it works as it should with other methods like "fs"). Also i have a folder inside my extention with all the necessery modules that i want to use. I tried to execute the same piece of code as a seperate .js file and it works fine. In my extention panel  a button is attached to call the function but nothing happens, it completely ignores it.

These are the functions i am trying to use:

 

<script src="./lib/CSInterface.js"></script>
		<script src="./lib/jquery-1.9.1.js"></script>
		<script type="text/javascript">

			function execute (command) {			
				const  exec  = require('child_process').exec
				exec(command, (err, stdout, stderr) => {
					process.stdout.write(stdout)
				})
			}
			function runPython() {
				execute('python pythonFile.py')
			}
		</script>

 

The runPython function is attached to a run-button in the index.html file that should execute the scirpt. I tried to use the "child_process" method with many differend compinations but i can't figure out what might be the probelm here. Any ideas on the subject? Has anyone expirienced something similar?
Thanks in advantage.

TOPICS
SDK
909
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 2 Correct answers

Adobe Employee , Nov 01, 2019 Nov 01, 2019
Here's a JavaScript function that builds and executes a Python command line, from within a panel. 


function processMoGRT (){
    var csInterface = new CSInterface();
    var OSVersion   = csInterface.getOSInformation();
    var filetypes = new Array();
    filetypes[0] = "mogrt";
    var result = window.cep.fs.showOpenDialog(false,false,"Select a .mogrt file", "~/Desktop",filetypes);
 
    var mogrtPath = result.data[0];


    var extPath    = csInterface.getSystemPath(SystemPath.EXTENSION);
   
...
Translate
Community Beginner , Feb 21, 2024 Feb 21, 2024
window.cep.process.createProcess("C:\\Windows\\explorer.exe", mogrtParentPath);

I also want to use this method, but what should I do if I report the error "window is undefined"

Translate
Adobe Employee ,
Nov 01, 2019 Nov 01, 2019
Here's a JavaScript function that builds and executes a Python command line, from within a panel. 


function processMoGRT (){
    var csInterface = new CSInterface();
    var OSVersion   = csInterface.getOSInformation();
    var filetypes = new Array();
    filetypes[0] = "mogrt";
    var result = window.cep.fs.showOpenDialog(false,false,"Select a .mogrt file", "~/Desktop",filetypes);
 
    var mogrtPath = result.data[0];


    var extPath    = csInterface.getSystemPath(SystemPath.EXTENSION);
    
    var sep        = "/";

    if (OSVersion.indexOf("Windows") > 0){
        sep = "\\\\";    
    }

    var mogrtParentPath = mogrtPath.substring(0, mogrtPath.lastIndexOf(sep));

    var pyPath = extPath + sep + 'Foiltop.py';

    var processResult = window.cep.process.createProcess("usr/bin/python", pyPath, mogrtPath);
    
    if (OSVersion.indexOf("Windows") >=0){
        window.cep.process.createProcess("C:\\Windows\\explorer.exe", mogrtParentPath);
    } else {
        window.cep.process.createProcess("/usr/bin/open", mogrtParentPath);
    }
    var resultFileName = mogrtParentPath + sep + "Foiltop_results.txt";
    
    var resultFileContents = window.cep.fs.readFile(resultFileName);//, cep.encoding.Base64);
    
    if (0 === result.err) {
        alert(resultFileContents.data);
    } else {
        alert("Failed to read results file.");
    }
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 Beginner ,
Feb 21, 2024 Feb 21, 2024
LATEST
window.cep.process.createProcess("C:\\Windows\\explorer.exe", mogrtParentPath);

I also want to use this method, but what should I do if I report the error "window is undefined"

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