Process::ORIGINAL_STDOUT and ORIGINAL_STDERR change

Hello,

I am upgrading my code from Crystal 0.30.1 to 0.35.1. When I compile with the newer version, I get the following error.
Error: undefined constant Process::ORIGINAL_STDOUT

These constants were defined in 0.30.1 and are not present in 0.35.1. I searched through the releases notes and through API, but could not find what I should replace these with. Can someone please point me in the right direction?

Thank you.

Sorry for the question. I found the answer here:

def run_cmd(cmd, args)
  stdout = IO::Memory.new
  stderr = IO::Memory.new
  status = Process.run(cmd, args: args, output: stdout, error: stderr)
  if status.success?
    {status.exit_code, stdout.to_s}
  else
    {status.exit_code, stderr.to_s}
  end
end
2 Likes

Sorry to resurrect such an old post, but I spent quite a bit of time today trying to do exactly that.

Would anyone be opposed to open a PR and add the above example to the API documentation for the Process.run ? I think this would be helpful for a lot of folks starting out with Crystal.

In my case I made a small modification to execute a command including it’s arguments:

def run_cmd(cmd)
  stdout = IO::Memory.new
  stderr = IO::Memory.new
  status = Process.run(cmd, output: stdout, error: stderr,shell: true)
  if status.success?
    {status.exit_code, stdout.to_s}
  else
    {status.exit_code, stderr.to_s}
  end
end
1 Like

Sure! Sent it over.

1 Like