0

I'm new to Groovy and Java and I have code like this:

def stdout = script.bat(
   script: "C:/Work/test.cmd",
   returnStdout: true
)

script.echo stdout

where script is groovy.lang.Script variable that comes into the constructor with super(script) and my function is defined in this class. I need to get an error message from my batch file execution and I'm trying to remake it using.execute() method like in this post. I have different question at stackoverflow regarding to receiving an error message from .bat() but this question is exactly about .execute(). When I write something like that

def proc = "C:/Work/test.cmd".execute();
def outputStream = new StringBuffer();
proc.waitForProcessOutput(outputStream, System.err);
script.echo(outputStream.toString());

I get an error java.io.IOException: error=2, No such file or directory considering I don't change the path to the cmd script. I've tried a lot of different ways: Runtime.getRuntime().exec(), used may be every overload of theese two methods have but I wasn't succeed

Update

Forgot to say that not only my file is not found but any cmd or powershell command (tasklist, cmd /c etc.). For cmd tried to specify the whole path to both SysWow64 and system32.

Tabigon
  • 21
  • 4
  • I'm running this command in Groovy. And forgot to mention that every cmd or powershell command is not found (tasklist cmd /c etc) – Tabigon Apr 09 '22 at 22:56

0 Answers0