[Gambas-user] Shell command including string containing a quote

Rob Kudla sourceforge-raindog2 at ...94...
Fri Jan 25 01:00:11 CET 2013


On 01/24/2013 12:59 PM, John Rose wrote:
> I have written a GUI to execute a command which involves selecting
> filenames (e.g. sCombinedPath below) to be used in a Shell command (as part
> of a Process). It works OK generally. However, if any filename includes a
> quote, it goes wrong.
> sCommand = "mplex -f 8 -o " & "'" & sCombinedPath & "' " &
> ...
>   hProcess = Shell sCommand

If you use Exec (which is not the same as Unix exec()), you can eliminate
quoting altogether.

http://gambasdoc.org/help/lang/exec

It takes an array, not a single string, and there's no shell redirection
because it doesn't invoke a shell. But you can just ignore the Read events
the process raises, and handle writing the log file (or doing something
fancier, I can't remember whether mplex provides useful progress
notifications and I don't seem to have any mpeg streams around that are old
enough for it to handle... ffmpeg definitely does, though) in the Error
event handler. So in your case it would be something like:

Dim mplex as Process
mplex = Exec [ "mplex", "-f", "8", "-o ", sCombinedPath, sVideoPath,
sAudioPath ]

Public Sub mplex_Error(output)
	' append output to the log file, or parse it for use in a progress bar or
whatever
End

I haven't tested this code, but you get the idea.

Rob





More information about the User mailing list