Jump to content

How to get wsl2 command to work?


Go to solution Solved by Earthshine,

Recommended Posts

Hello, I'm currently using the following code:

$LDSconverterPID = Run ("wsl /bin/bash -c " & Chr(34) & "cat " &  $sCaptureFileName & " | ld-lds-converter -u |  ffmpeg -hide_banner -loglevel error -f s16le -ar 40k -ac 1 -i - -acodec flac -compression_level 11 -f ogg '/mnt/v/_new_workflow/1-compressed/" & $baseFileName & ".ldf'" & Chr(34), "", @SW_HIDE, $STDERR_MERGED)
WriteToLog("$LDSconverterPID: " & $LDSconverterPID)
Do
    $sOutput = StdoutRead($LDSconverterPID)
    If $sOutput <> "" Then WriteToLog("StdOut: " & $sOutput)
    Until @error ; Exit the loop if the process closes or StdoutRead returns an error.
WriteToLog("@error: " & @error)
WriteToLog("@extended: " & @extended)
WriteToLog("StdErr: " & StderrRead($LDSconverterPID))

The command doesn't run and I get the following output:

2023-05-05 13:23:03 : $LDSconverterPID: 0
2023-05-05 13:23:03 : @error: 2
2023-05-05 13:23:03 : @extended: 0
2023-05-05 13:23:03 : StdErr:

The command line I use for Run is:

wsl /bin/bash -c "cat /home/david/captures/RF-Sample___2023-05-04_17-00-22.lds | ld-lds-converter -u |  ffmpeg -hide_banner -loglevel error -f s16le -ar 40k -ac 1 -i - -acodec flac -compression_level 11 -f ogg '/mnt/v/_new_workflow/1-compressed/Betamax 0 2023-05-05 13.22.ldf'"

When I copy/paste this into the Command Prompt, this runs fine.

How should I modify my code to get the same result from AutoIT? TIA

Link to comment
Share on other sites

try this if is ok

$sCaptureFileName = "/home/david/captures/RF-Sample___2023-05-04_17-00-22.lds"

$cmd1 = "wsl /bin/bash -c ""cat " & $sCaptureFileName
$cmd1 &= " | ld-lds-converter -u |  ffmpeg -hide_banner -loglevel error -f s16le -ar 40k -ac 1 -i - -acodec flac -compression_level 11 -f ogg"
$cmd1 &= " '/mnt/v/_new_workflow/1-compressed/Betamax 0 2023-05-05 13.22.ldf'"""

$cmd2 = 'wsl /bin/bash -c "cat ' & $sCaptureFileName
$cmd2 &= ' | ld-lds-converter -u |  ffmpeg -hide_banner -loglevel error -f s16le -ar 40k -ac 1 -i - -acodec flac -compression_level 11 -f ogg'
$cmd2 &= " '/mnt/v/_new_workflow/1-compressed/Betamax 0 2023-05-05 13.22.ldf'" & '"'

$cmd3 = "wsl /bin/bash -c ""cat " & $sCaptureFileName
$cmd3 &= " | ld-lds-converter -u |  ffmpeg -hide_banner -loglevel error -f s16le -ar 40k -ac 1 -i - -acodec flac -compression_level 11 -f ogg"
$cmd3 &= " '/mnt/v/_new_workflow/1-compressed/Betamax 0 2023-05-05 13.22.ldf'"""

ConsoleWrite("$cmd1=" & $cmd1 & @CRLF)
ConsoleWrite("$cmd2=" & $cmd2 & @CRLF)
ConsoleWrite("$cmd3=" & $cmd3 & @CRLF)

:welcome:  to the forum

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Thanks for your help @ioa747!

All three variables yield identical strings in the console window, as I understand it, wsl isn't actually executed.

I've also tried

$LDSconverterPID = Run ($cmd1, "", @SW_HIDE, $STDERR_MERGED)
$LDSconverterPID = Run ($cmd2, "", @SW_HIDE, $STDERR_MERGED)
$LDSconverterPID = Run ($cmd3, "", @SW_HIDE, $STDERR_MERGED)

but in all cases $LDSconverterPID is 0.

Any idea how to get this actually executed?

Thanks for your welcome to the forum!

Link to comment
Share on other sites

i am not familiar with wsl . This was an example of how to pass the string to the Run() ,  it is the same command with a different approach

I saw the The command line I use for Run is: ...  and thought that this is the command you want to send to the wsl

Edit:
try something simpler to begin with, until it gets going

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

It was a good idea to start simpler.

$CMD = "dir"
$testPID = Run(@ComSpec & " /c " & $CMD, "", @SW_HIDE, $STDERR_MERGED)
Do
    $sOutput = StdoutRead($testPID)
    If $sOutput <> "" Then WriteToLog("StdOut: " & $sOutput)
Until @error ; Exit the loop if the process closes or StdoutRead returns an error.

This gives me whatever is in the directory where the .au3 script is saved.

Now when I change $CMD to:

$CMD = "wsl ls"

I get:

2023-05-05 17:18:38 : StdOut: 'wsl' is not recognized as an internal or external command, operable program or batch file.

I get the same error when I use "c:\windows\system32\wsl.exe" instead.

Why does Run behave differently from running the same command from the Command Prompt?

Link to comment
Share on other sites

All the example commands on that page work in principle, both in PS and CMD. But I still can't get them invoked properly from AutoIT... It's probably trivial, I just don't yet know what I'm missing...

Link to comment
Share on other sites

when i run it my firewall asks for the permission for the program, but it doesn't give me anything in the console

#AutoIt3Wrapper_UseX64=y
#RequireAdmin
#include <AutoItConstants.au3>

ConsoleWrite("" & @SystemDir & @CRLF)

;~ $CMD = "dir"
$CMD =  'wsl --list --online'

$testPID = Run(@ComSpec & " /c " & $CMD, "", @SW_HIDE, $STDERR_MERGED)
Do
    $sOutput = StdoutRead($testPID)
    If $sOutput <> "" Then ConsoleWrite($sOutput & @CRLF)
Until @error ; Exit the loop if the process closes or StdoutRead returns an error.

 

I know that I know nothing

Link to comment
Share on other sites

You don’t put WSL in front of the commands, to list the directories simply 

ls

ls -la will list the Director a long style with details

it appears that you are not familiar with Linux commands

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

19 hours ago, Earthshine said:

it appears that you are not familiar with Linux commands

My use case is that I'd like to run Linux commands from an AutoIT script running on Windows. I use WSL as the bridge from Windows to the Linux subsystem.

How would you script commands to be run in the Linux subsystem from AutoIT?

Link to comment
Share on other sites

$cmd = “ls -la”

 

Open a command prompt, and then type in bash and hit enter

Here you can practice all the Linux commands

you can get help too

ls —help or ls —?

 

in your script, you are passing parameters to bash.exe that is most likely running from a command prompt

Just passed regular Linux command to it like you would on the command line

you will need to run a bash session most likely I think you can just call bash by yourself and not pass it to a command prompt because the command prompt doesn’t know what WSL

 

i would try it just like you’re using the command prompt but use bash instead

Let us know

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Solution

This is exactly what you want to do so read that thread and copy the code, and play with it until you understand it

 

$iPID = runwait('cmd /c bash ' & $sScriptDir)

you will need to do something like that after you build your command

 

 

read that thread too

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...