# Help with system() call and pipe

**URL:** <https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154>\
**Category:** Ruby\
**Created:** [July 11, 2007, 11:26pm UTC](https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154 "2007-07-11T23:26:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoanS\_Alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@DoanS\_Alex](https://www.ruby-forum.com/u/DoanS_Alex)\
**Post date:** [July 11, 2007, 11:26pm UTC](https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154/1 "2007-07-11T23:26:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DoanS\_Alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@DoanS\_Alex](https://www.ruby-forum.com/u/DoanS_Alex)\
**Post date:** [July 12, 2007, 1:15am UTC](https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154/2 "2007-07-12T01:15:58Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![DoanS\_Alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@DoanS\_Alex](https://www.ruby-forum.com/u/DoanS_Alex)\
**Post date:** [July 12, 2007, 2:03pm UTC](https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154/3 "2007-07-12T14:03:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DoanS\_Alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@DoanS\_Alex](https://www.ruby-forum.com/u/DoanS_Alex)\
**Post date:** [July 12, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/help-with-system-call-and-pipe/109154/4 "2007-07-12T19:49:57Z")

</div>

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.
