Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Process: ensure chdir is a string #13503

Merged
merged 5 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion spec/std/process_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand All @@ -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)
devnote-dev marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
2 changes: 1 addition & 1 deletion src/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down