Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > mixing string formatting with system exec

Reply
Thread Tools

mixing string formatting with system exec

 
 
Nate St.Germain
Guest
Posts: n/a
 
      09-26-2010
noob question…

why does this line produce the following result?

%x("%s %s" % ['/usr/bin/touch', '/tmp/test'])

error:
sh: line 0: fg: no job control

i don't necessarily need to use string formatting or substitution here,
just curious about the result.

thanks.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-26-2010
On 26.09.2010 21:26, Nate St.Germain wrote:
> noob question…
>
> why does this line produce the following result?
>
> %x("%s %s" % ['/usr/bin/touch', '/tmp/test'])
>
> error:
> sh: line 0: fg: no job control
>
> i don't necessarily need to use string formatting or substitution here,
> just curious about the result.
>
> thanks.


%x is backticks and the contents between brackets are passed unmodified
to the shell:

Robert@babelfish ~
$ ruby19 -e 'p %x[ls a]'
ls: cannot access a: No such file or directory
""

Robert@babelfish ~
$ ruby19 -e 'p %x["ls a"]'
sh: ls a: command not found
""

You are essentially doing the same as this:

irb(main):002:0> system '"%s %s" % [\'/usr/bin/touch\', \'/tmp/test\']'
sh: line 0: fg: no job control
=> false

You get the same if you call bash as sh directly:

Robert@babelfish ~
$ /bin/sh -c '"%s %s"'
/bin/sh: line 0: fg: no job control


Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
 
 
 
Nate St.Germain
Guest
Posts: n/a
 
      09-27-2010
Robert Klemme wrote:

> %x is backticks and the contents between brackets are passed unmodified
> to the shell:



ahh, got it. thanks, robert.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Exec/System call with spaces in exec path problem ... Random Task Perl Misc 12 12-04-2005 10:03 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM
Backup Exec 9.1: The Backup Exec job engine system service is not responding Christian Falch Computer Support 1 06-23-2004 02:22 AM



Advertisments