From: Paul Lutus Date: 2006-11-25T04:50:24+09:00 Subject: Re: invoke system command from within a method Moritz Reiter wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi all, > > I am new to Ruby and want to make a Ruby script for the network > configuration of my notebook as an exercise. Now I encountered a problem > which is pretty strange to me: > > I want to invoke '/etc/init.d/networking restart' from within my Ruby > program. If I create a file with the line > > %x{ /etc/init.d/networking restart } > > it works like I would expect. The networking init script gets invoked > and correctly processed. > > But if I do something like this: > > - -->8-- > class Netconf > def restart > puts %x{ /etc/init.d/networking restart } > end > end > > netconf = Netconf.new > netconf.restart > - --8<-- > > I get some output from the init script What output? > but it doesn't seem to actually > do anything. It should have worked, unless of course you were not root. By the way, running this script as root is (1) a very bad idea, and (2) essential to make it work. Were you root? What if anything was printed by the method? Is the above listing an exact copy of your code? > It does not reconfigure my eth's Restarting the network doesn't reconfigure anything. What did you expect to happen, what happened instead, how do they differ? > in oppostion to the > behaviour described above if don't make the system call from within a > method. Are you sure about that? Have you tried stopping your network in advance, then running the script as root, just to see if the network comes back up? Again, what was printed out when the script ran? -- Paul Lutus http://www.arachnoid.com