Page 1 of 1
Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 8:58 am
by Seymour Clufley
I'm using
SoX on Windows to mix multiple audio files into one. The code is normal:
Code: Select all
prog = RunProgram(#Sox,param$,"P:\sox_exper\",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
where param$ variable is:
Code: Select all
-m "|sound1.wav -p -v 1.00" "|sound2.wav -p -v 0.50" "P:\sox_exper\mix.wav"
The param$ uses pipes because I want to augment each file (changing its volume) before mixing them together.
Unfortunately, I'm getting a SoX error:
FAIL formats: can't open input pipe `|tophat.wav -p -v 0.50': premature EOF
Apparently this is happening because SoX
requires the word "sox" at the start of each pipe.
I was aware that PB doesn't like that, but I tried it anyway. I changed the param$ variable to:
Code: Select all
-m "|sox sound1.wav -p -v 1.00" "|sox sound2.wav -p -v 0.50" "P:\sox_exper\mix.wav"
This results in the error message:
'sox' is not recognized as an internal or external command
I suspect this is to do with Windows vs. Linux. Does anyone have any ideas of a workaround?
Re: Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 11:05 am
by mrv2k
Assuming that the command line works from a DOS prompt, you'd need to format it like this
Code: Select all
param$="-m "+#DOUBLEQUOTE$+"|sox sound1.wav -p -v 1.00"+#DOUBLEQUOTE$+" "+#DOUBLEQUOTE$+"|sox sound2.wav -p -v 0.50"+#DOUBLEQUOTE$+" "+#DOUBLEQUOTE$+"P:\sox_exper\mix.wav"+#DOUBLEQUOTE$
This gives me...
Code: Select all
-m "|sox sound1.wav -p -v 1.00" "|sox sound2.wav -p -v 0.50" "P:\sox_exper\mix.wav"
... as the parameter.
I've found it's best to test on a DOS prompt and mirror the command into Purebasic. Also having a console window running can help too.
Re: Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 5:40 pm
by Seymour Clufley
Thank you, Mrv2k, but the formatting you suggest is exactly the formatting that I'm trying, and which is raising the error:
'sox' is not recognized as an internal or external command
Re: Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 5:53 pm
by Marc56us
Try with escape sequence, like this:
Code: Select all
param$ = ~"-m \"|sound1.wav -p -v 1.00\" \"|sound2.wav -p -v 0.50\" \"P:\\sox_exper\\mix.wav\""
But IMHO this is the pipe (|) that cause problem to RunProgram() function.
Alternative: Create a batch file and run it with
cmd / c

Re: Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 10:00 pm
by pf shadoko
I am not a great command line specialist but it seems to me that quotes are useful for words that may contain spaces,
so often the paths
I'd rather see this:
param$ = ~"-m| \"sound1.wav\" -p -v 1.00| \"sound2.wav\" -p -v 0.50 \"P:\\sox_exper\\mix.wav\""
or even, in this case, without quotes.
Re: Command line program NEEDS its name at start of parameters
Posted: Wed Apr 28, 2021 10:17 pm
by infratec
RunProgram() runs a program directly.
A pipe is a 'command' of the 'shell'.
It can only work if you run the 'shell'
You need to run
'cmd' with parameters '/C sox -m | ...| ..'
Re: Command line program NEEDS its name at start of parameters
Posted: Thu Apr 29, 2021 12:38 am
by kenmo
Is #Sox a full path to the program?
Try this before the RunProgram()
Code: Select all
SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + ";" + GetPathPart(#Sox))
Re: Command line program NEEDS its name at start of parameters
Posted: Thu Apr 29, 2021 2:11 am
by ChrisR
The volume must be specified before the audio file
Code: Select all
sox -m "|sox -v 1 Ring03.wav -p" "|sox -v 0.5 Ring08.wav -p" Ring.wav
It looks good with
Code: Select all
SetCurrentDirectory("E:\Temp\sox")
param$ = "-m " + #DQUOTE$ + "|sox -v 1 Ring03.wav -p" + #DQUOTE$ + " " + #DQUOTE$ + "|sox -v 2 Ring08.wav -p" + #DQUOTE$ + " Ring.wav"
RunProgram("Sox.exe", param$, GetCurrentDirectory(), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
It works also without pipe
Code: Select all
SetCurrentDirectory("E:\Temp\sox")
param$ = "-m -v 1 Ring03.wav -v 2 Ring08.wav Ring.wav"
RunProgram("Sox.exe", param$, GetCurrentDirectory(), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
Re: Command line program NEEDS its name at start of parameters
Posted: Mon May 03, 2021 11:01 am
by Seymour Clufley
Thank you for everyone's help here. I was relieved to find (from ChrisR) that the job could be done without piping at all.