'How to run WSL programs within AutoIt?
I'm trying to run a linux console application using AutoIt. So far I was successful in generating a batch file with the following command:
wsl /home/ggeorgiev/DD/myprogram --json_file /mnt/c/Users/ggeorgiev/my_input.json
This batch runs successfully from cmd, powershell and also when I just double click on it in the explorer. So, I'm thinking that part is okay.
In AutoIt, I'm trying to run the same batch file ("JBDD_start.bat") using the following function:
Func RunJBDD()
Local $iPID = Run("cmd.exe " & "JBDD_start.bat", @WorkingDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD,$RUN_CREATE_NEW_CONSOLE ))
Local $sOutput = ""
While 1
$sOutput &= StdoutRead($iPID)
If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
ExitLoop
EndIf
MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
WEnd
$sOutput = ''
While 1
$sOutput &= StderrRead($iPID)
If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
ExitLoop
EndIf
MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput)
WEnd
EndFunc
It doesn't show anything in the StdErr nor in StdOut message boxes. Any suggestions on what may have gone wrong or how to find what happens "behind the scenes" are highly appreciated.
Solution 1:[1]
Try this, maybe it helps to get your output.
ConsoleWrite( _getDOSOutput('ping 4.2.2.2') & @CRLF)
Func _getDOSOutput($command)
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
$text &= StdoutRead($Pid, False, False)
If @error Then ExitLoop
Sleep(10)
WEnd
Return $text
EndFunc ;==>_getDOSOutput
Solution 2:[2]
I'm not familiar with AutoIt, but I'm going to take an educated guess here. If I'm wrong, at least it might help someone else.
I notice that AutoIt comes with both 32-bit and 64-bit executables. Make sure you are either:
- Using the 64-bit version to execute your batch file
- Or, if you really do need to run the 32-bit version of AutoIt, call
C:\Windows\Sysnative\wsl.exe
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xenobiologist |
| Solution 2 | NotTheDr01ds |
