I’m quite confused reading the doc of Ruby’s system method here. I’m not sure what are commands and what are options. What do I do if I want to execute the following?
wget -pk -nd -P /public/google www.google.com
For security reasons, I’d like to use one of the versions that uses no shell (the second and third forms in the URL I gave, rather than the first)
Consider the examples:
The first one passes the string
'echo *'to the shell to be parsed and executed; that’s whysystem('echo *')produces the same output as sayingecho *from the shell prompt: you get a list of files in the current directory. The corresponding argument form is:The second one bypasses the shell entirely. It will look for
echoin thePATHand then execute it with the string'*'as its argument. Since the shell expands wildcards (at least on unixy systems), the*will stay as a simple*and you’ll see*as the output. The corresponding argument form here is:The third form:
is used when you want to execute
cmdnamebut have it show up with a different name inpslistings and such. You can see this in action by opening two terminals. Open upirbin one of them and say:then quickly switch to the other and look at the
pslisting. You should seesleep 10in there. But, if you give this toirb:and check the
pslisting, you’ll seepancakes 10. Similar two-terminal tricks will show you ashell -c sleep 10if you saysystem('sleep 10').If you supply a Hash as the first argument, then that Hash is used as the environment variables for the spawned process. If you supply a Hash as the final argument, then that Hash is used as options; further documentation on the arguments is, as noted in the
systemdocumentation, available underKernel#spawn.