Ruby run shell command in a specific directory

后端 未结 6 1369
死守一世寂寞
死守一世寂寞 2020-12-01 07:23

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

%x[#{cmd}]

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

Is there a simila

6条回答
  •  不思量自难忘°
    2020-12-01 07:59

    Maybe it's not the best solution, but try to use Dir.pwd to get the current directory and save it somewhere. After that use Dir.chdir( destination ), where destination is a directory where you want to run your command from. After running the command use Dir.chdir again, using previously saved directory to restore it.

提交回复
热议问题