Execvp (cat /tmp/.yWcP8dactual | json_reformat > /tmp/.yWcP8dactual.2): No such file or directory: No such file or directory (Errno)

My code is basically:

    cmd = "cat /tmp/.yWcP8dactual | json_reformat > /tmp/.yWcP8dactual.2"
    stdout = IO::Memory.new
    stderr = IO::Memory.new
    p = Process.new(cmd, output: stdout, error: stderr)
    status = p.wait

results in:

execvp (cat /tmp/.yWcP8dactual | json_reformat > /tmp/.yWcP8dactual.2): No such file or directory: No such file or directory (Errno)
         from /usr/share/crystal/src/process.cr:296:52 in 'initialize:args:output:error:shell'
         from /usr/share/crystal/src/process.cr:251:3 in 'new:args:output:error:shell'

but when I run cat /tmp/.yWcP8dactual | json_reformat > /tmp/.yWcP8dactual.2 in my terminal right after, it works.

The command you are running is not actually a command, as in executable file, but a shell command with pipes and redirects which are things a shell does.

you need to specify to run the command with shell like this:

p = Process.new(cmd, shell: true, output: stdout, error: stderr)