#2883 Run fan commands using process class

FMahony Thu 29 Dec 2022

I'm dabbling with the process class and can do basic actions such as ping, ipconfig, etc but am having issues running fan commands. I'm on a Windows machine and have tried it with and without the bin folder in Path. The snippet below is without.

Process cmdLine := Process(["./fan", "-version"])
cmdLine.dir = File(Uri("${Env.cur.homeDir}bin/"))
echo(cmdLine.dir)
cmdLine.run()

cmdLine.join()
cmdLine.kill()

The error I get is "CreateProcess error=193, %1 is not a valid Win32 application".

SlimerDude Thu 29 Dec 2022

Hi FMahony,

The reason behind the error message is because fan is actually fan.bat which, in the world of Win32, is NOT a valid executable that can be run via a Process.

Your options are to either start a new Windows Command Interpreter that can interpret the .bat file:

args       := ["cmd", "/C", "fan.bat", "-version"]
cmdLine    := Process(args)
cmdLine.run.join

Or to start a new Java process directly:

homeDir    := Env.cur.homeDir
classpath  := homeDir + `lib/java/sys.jar`
args       := ["java", "-cp", classpath.osPath, "-Dfan.home=${homeDir.osPath}", "fanx.tools.Fan", "-version"]
cmdLine    := Process(args)
cmdLine.run.join

FMahony Thu 29 Dec 2022

Thanks, SlimerDude! Both options worked like a charm and the explanation was much appreciated.

Login or Signup to reply.