Command line program NEEDS its name at start of parameters

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Command line program NEEDS its name at start of parameters

Post 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?
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
mrv2k
User
User
Posts: 51
Joined: Fri Jan 20, 2012 3:40 pm
Location: SE England
Contact:

Re: Command line program NEEDS its name at start of parameters

Post 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.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Command line program NEEDS its name at start of parameters

Post 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
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Command line program NEEDS its name at start of parameters

Post 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

:wink:
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 289
Joined: Thu Jul 09, 2015 9:07 am

Re: Command line program NEEDS its name at start of parameters

Post 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.
infratec
Always Here
Always Here
Posts: 6867
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Command line program NEEDS its name at start of parameters

Post 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 | ...| ..'
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Command line program NEEDS its name at start of parameters

Post by kenmo »

Is #Sox a full path to the program?

Try this before the RunProgram()

Code: Select all

SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + ";" + GetPathPart(#Sox))
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Command line program NEEDS its name at start of parameters

Post 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)
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Command line program NEEDS its name at start of parameters

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply