diff --git a/spec/std/process_spec.cr b/spec/std/process_spec.cr index 9292fd25aec9..628baa93c39e 100644 --- a/spec/std/process_spec.cr +++ b/spec/std/process_spec.cr @@ -180,7 +180,7 @@ describe Process do $?.exit_code.should eq(0) end - it "sets working directory" do + it "sets working directory with string" do parent = File.dirname(Dir.current) command = {% if flag?(:win32) %} "cmd.exe /c echo %cd%" @@ -193,6 +193,19 @@ describe Process do value.should eq "#{parent}#{newline}" end + it "sets working directory with path" do + parent = Path.new File.dirname(Dir.current) + command = {% if flag?(:win32) %} + "cmd.exe /c echo %cd%" + {% else %} + "pwd" + {% end %} + value = Process.run(command, shell: true, chdir: parent, output: Process::Redirect::Pipe) do |proc| + proc.output.gets_to_end + end + value.should eq "#{parent}#{newline}" + end + pending_win32 "disallows passing arguments to nowhere" do expect_raises ArgumentError, /args.+@/ do Process.run("foo bar", {"baz"}, shell: true) diff --git a/src/process.cr b/src/process.cr index 12173c68b4a7..159b08b39eaa 100644 --- a/src/process.cr +++ b/src/process.cr @@ -243,7 +243,7 @@ class Process fork_output = stdio_to_fd(output, for: STDOUT) fork_error = stdio_to_fd(error, for: STDERR) - pid = Crystal::System::Process.spawn(command_args, env, clear_env, fork_input, fork_output, fork_error, chdir) + pid = Crystal::System::Process.spawn(command_args, env, clear_env, fork_input, fork_output, fork_error, chdir.try &.to_s) @process_info = Crystal::System::Process.new(pid) fork_input.close unless fork_input.in?(input, STDIN)