2009/1/7 Gu stav <gustav / vonsydow.tv>:
> I'm trying to run multiple commands in the shell from ruby but I can't
> seem to grasp how I keep the "state" from the previous shell command.
>
> For example, how would I perform the following sequence of commands in
> ruby:
>
> 1. cd /dir
> 2. ls
>
> Not counting "ls /dir" that is ;)
>
> I've tried using:
>
> system "cd /dir"
> system "ls"

two seperate calls do not work because every system-call creates a new
shell process. If you do a 'cd' the first shell does the 'cd' and is
then terminated.
The second system call starts a new shell process, which does not know
about the former cd.

You can call system("(cd /dir; ls)")

The () inside the system call executes all the commands in one shell process.

-Thomas

-- 
Thomas Preymesser
thopre / gmail.com
http://thopre.googlepages.com/
http://thopre.wordpress.com/