Page 1 of 1

how to run a multi-line command line or a .bat file in scripting

Posted: Tue Aug 16, 2022 1:08 pm
by MercuryLamp
how to run a multi-line command line or a .bat file in scripting
has tried Process.execute(cmd1 & cmd2) failed

Re: how to run a multi-line command line or a .bat file in scripting

Posted: Tue Aug 16, 2022 5:38 pm
by freddyp
If the batch file is fixed

Code: Select all

var batchFile = "E:\\path\\to\\batchfile.bat";
var processOptions = ["cmd","/C",batchFile];
var result = Process.execute(processOptions);
Not tested! If the contents are variable you will have to write a temporary batch file of course.

Code: Select all

var batchFilePath = job.createPathWithName(job.getNameProper()+".bat";
I strongly advise against doing this in legacy scripting. It is just as easy to do this in Node.js. The package that I use for running external commands is execa (https://www.npmjs.com/package/execa).

Re: how to run a multi-line command line or a .bat file in scripting

Posted: Fri Aug 19, 2022 2:03 am
by MercuryLamp
Yess.. thank you very much it is working :D