Copy link to clipboard
Copied
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.
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);
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"
Copy link to clipboard
Copied
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.");
}
Copy link to clipboard
Copied
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"