icn icn - 1 year ago 98
Bash Question

Ruby run shell command in a specific directory

I know how to run a shell command in Ruby like:


But, how do I specify a directory to run this command?

Is there a similar way of shelling out, similar to
in Python:

subprocess.Popen(r'c:\mytool\tool.exe', cwd=r'd:\test\local')


Answer Source

You can use the block-version of Dir.chdir. Inside the block you are in the requested directory, after the Block you are still in the previous directory:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download