diff --git a/src/crystal/system/win32/process.cr b/src/crystal/system/win32/process.cr index fa0754116d2e..46e1d25ee9aa 100644 --- a/src/crystal/system/win32/process.cr +++ b/src/crystal/system/win32/process.cr @@ -256,8 +256,9 @@ struct Crystal::System::Process process_info = LibC::PROCESS_INFORMATION.new if command_args.is_a?(String) + raise ArgumentError.new("Command line contains newline") if command_args.includes?('\n') result = LibC.CreateProcessW( - CMD_EXE, System.to_wstr(%(/c "#{command_args}")), nil, nil, true, LibC::CREATE_UNICODE_ENVIRONMENT, + CMD_EXE, System.to_wstr(%(/s /c "#{command_args}")), nil, nil, true, LibC::CREATE_UNICODE_ENVIRONMENT, make_env_block(env, clear_env), chdir.try { |str| System.to_wstr(str) } || Pointer(UInt16).null, pointerof(startup_info), pointerof(process_info) ) diff --git a/src/process.cr b/src/process.cr index 8509ea730341..31718733b796 100644 --- a/src/process.cr +++ b/src/process.cr @@ -234,7 +234,7 @@ class Process # * On Windows this is implemented by passing the string as-is to `%COMSPEC%`, # and passing *args* is not supported. The user is responsible for correctly # quoting the command string, as `Process.quote_windows` does not handle - # this. + # this. Additionally, *command* cannot contain the newline character (`\n`). # # Raises `IO::Error` if executing the command fails (for example if the executable doesn't exist). def initialize(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = false,