D
Dale Martenson
Here is something that I am struggling with -- I would like to execute a
command string with an IO.popen call that contains embedded double quote
characters. When I build the initial command string everything seems to
work, but once I pass is on to IO.popen, it seems to mess up the double
quotes.
Here is my example, I want to execute the following command from a Ruby
program:
pppd connect "chat -v '' ATZ OK ATDT5551234 CONNECT '' ogin:
username word: password" /dev/ttyS0 115200 -detach crtscts modem defaultroute
I create the command string by the long and somewhat ugly ruby command:
command = "pppd connect \\\"chat -v '' #{initialization_command}
#{initialization_response} #{dial_command} #{dial_response} ''
#{username_prompt} #{username} #{password_prompt} #{password}\\\"
#{device.name} #{speed} -detach crtscts modem defaultroute\r\n"
In this case, I escaped the escaped the double quote. I have also tried
various combinations of multiple double quotes (4 in a row, etc.).
If I now echo the command using a system call:
system( "echo #{command}" )
the command seems to echo the desired result:
pppd connect "chat -v ATZ OK ATD5551234 CONNECT ogin: username
word: password" /dev/ttyS0 115200 -detach crtscts modem defaultroute
But when I pass it to IO.popen, I get
pppd: unrecognized option '-v'
pppd version 2.4.1
Usage: pppd [ options ], where options are:
<device> Communicate over the named device
<speed> Set the baud rate to <speed>
<loc>:<rem> Set the local and/or remote interface IP
addresses. Either one may be omitted.
asyncmap <n> Set the desired async map to hex <n>
auth Require authentication from peer
connect <p> Invoke shell command <p> to set up the
serial line
crtscts Use hardware RTS/CTS flow control
defaultroute Add default route through interface
file <f> Take options from file <f>
modem Use modem control lines
mru <n> Set MRU value to <n> for negotiation
See pppd(8) for more options.
which is caused by that the double quotes are being stripped by
IO.popen. How do I avoid this?
Thanks,
Dale Martenson
command string with an IO.popen call that contains embedded double quote
characters. When I build the initial command string everything seems to
work, but once I pass is on to IO.popen, it seems to mess up the double
quotes.
Here is my example, I want to execute the following command from a Ruby
program:
pppd connect "chat -v '' ATZ OK ATDT5551234 CONNECT '' ogin:
username word: password" /dev/ttyS0 115200 -detach crtscts modem defaultroute
I create the command string by the long and somewhat ugly ruby command:
command = "pppd connect \\\"chat -v '' #{initialization_command}
#{initialization_response} #{dial_command} #{dial_response} ''
#{username_prompt} #{username} #{password_prompt} #{password}\\\"
#{device.name} #{speed} -detach crtscts modem defaultroute\r\n"
In this case, I escaped the escaped the double quote. I have also tried
various combinations of multiple double quotes (4 in a row, etc.).
If I now echo the command using a system call:
system( "echo #{command}" )
the command seems to echo the desired result:
pppd connect "chat -v ATZ OK ATD5551234 CONNECT ogin: username
word: password" /dev/ttyS0 115200 -detach crtscts modem defaultroute
But when I pass it to IO.popen, I get
pppd: unrecognized option '-v'
pppd version 2.4.1
Usage: pppd [ options ], where options are:
<device> Communicate over the named device
<speed> Set the baud rate to <speed>
<loc>:<rem> Set the local and/or remote interface IP
addresses. Either one may be omitted.
asyncmap <n> Set the desired async map to hex <n>
auth Require authentication from peer
connect <p> Invoke shell command <p> to set up the
serial line
crtscts Use hardware RTS/CTS flow control
defaultroute Add default route through interface
file <f> Take options from file <f>
modem Use modem control lines
mru <n> Set MRU value to <n> for negotiation
See pppd(8) for more options.
which is caused by that the double quotes are being stripped by
IO.popen. How do I avoid this?
Thanks,
Dale Martenson