Help with system() call and pipe

I’m using system call and pipping the output to a log. Something funny
happen when I have more then two escaped quotes and ‘>>’ in my call. Can
someone shed some light on the issue:

Case:
command_to_execute = ““c:/program files/cvs.exe” -q export -r HEAD -d
TEST “1sks/src folder” >> output.log”
system( command_to_execute )

This call will error out stating that c:/program is not recognized. Now
if I remove the >>, the command work fine. Or if I replace the module
(“1sks/src folder”) to a module that doesn’t require the quote like:
command_to_execute = ““c:/program file/cvs.exe” -q export -r HEAD -d
TEST 1sks/build >> ouput.log”

Then system work fine.

Below are some test with pinging cmd, save to file call test.rb.
Test Case:
Tried it on the ping command with quoting and >, gave me the same issue.
(I dont need the quote with ping, but they are there to represent issue
where I would need the escape quote and the system command is giving me
issue.)
a = "“C:/WINDOWS/system32/ping.exe” “BFI3CHL671” >> out.txt "
system(a)

output:
‘C:/WINDOWS/system32/ping.exe" "BFI3CHL671’ is not recognized as an
internal or external command,
operable program or batch file.


Without the >:
a = "“C:/WINDOWS/system32/ping.exe” “BFI3CHL671"”
system(a)

output:
Pinging BFI3CHL671 [114.19.9.181] with 32 bytes of data:

Reply from 114.19.9.181: bytes=32 time<1ms TTL=38
Reply from 114.19.9.181: bytes=32 time=1ms TTL=38
Reply from 114.19.9.181: bytes=32 time<1ms TTL=38
Reply from 114.19.9.181: bytes=32 time<1ms TTL=38

Ping statistics for 114.19.9.181:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms


Without the third/fourth escaped quote:
a = "“C:/WINDOWS/system32/ping.exe” BFI3CHL671 >> out.txt "
system(a)

ouput:
out.txt contain the appropriate lines

Doan, Alex wrote:

I’m using system call and pipping the output to a log. Something funny
happen when I have more then two escaped quotes and ‘>>’ in my call. Can
someone shed some light on the issue:

Case:
command_to_execute = ““c:/program files/cvs.exe” -q export -r HEAD -d
TEST “1sks/src folder” >> output.log”
system( command_to_execute )

This call will error out stating that c:/program is not recognized.

Isn’t this because you need to escape the space, too? so that
command_to_execute = ““c:/program\ files/cvs.exe” …”

Now if I remove the >>, the command work fine.
To me, that’s the weird thing here…

On 2007-07-12 08:15:04 +0900 (Thu, Jul), Richard L. wrote:

This call will error out stating that c:/program is not recognized.

Isn’t this because you need to escape the space, too? so that
command_to_execute = ““c:/program\ files/cvs.exe” …”

Now if I remove the >>, the command work fine.
To me, that’s the weird thing here…

Isn’t it better to use the system() with multiple parameters in this
case?
as in: system(‘c:/program files/cvs.exe’, ‘-q’,‘export’, … )

Then you don’t need to escape the special characters. I am not sure
whether this works on Windows.
I know, it might not allow redirecting (’>> output.log’), but I recall
DOS did not handle the redirections for the programs and the programs
themselves had to.

Maybe popen() would be acceptable solution?

Gentleman,
Thanks for the reply, I work around it. I just added the executable
program to the environment PATH and remove the needs for quote escaped
string.