nobilik
nobilik

Reputation: 736

How to start process with output to log file?

I try to do it this way, but nothing happens.

Process.new("app_name >> app_name.log")

What is the proper syntax?

Upvotes: 1

Views: 327

Answers (2)

Stephie
Stephie

Reputation: 3175

You can do this entirely within Crystal without spawning a shell using the output option of Process.new.

File.open("app_name.log", "a") do |file|
  Process.new("app_name", output: file)
end

Upvotes: 6

Johannes Müller
Johannes Müller

Reputation: 5661

Process.new by default executes the given command directly without a shell, therefore shell extensions like pipes do not work. But it accepts an argument shell, which executes the command with /bin/sh if set to true.

Process.new("app_name >> app_name.log", shell: true)

Upvotes: 3

Related Questions