Hello, I would like when the software I’m coding launch a process visible in the terminal, to as well write this output in a file (to trace everything, so a log).
For example with this process:
tasks = <<-CODE
require "./RequiredLibraries"
Ism = ISM::CommandLine.new
Ism.loadSoftwareDatabase
Ism.loadSettingsFiles
require "./#{requirePath}"
target = Target.new("#{targetPath}")
begin
target.download
target.check
target.extract
target.patch
target.prepare
target.configure
target.build
target.prepareInstallation
target.install
target.clean
rescue
exit 1
end
CODE
File.write("ISM.task", tasks)
process = Process.run("crystal",args: ["ISM.task"],output: :inherit,error: :inherit,)
if !process.success?
break
end
If you just want to write to multiple IOs, you could prob just use IO::MultiWriter - Crystal 1.6.2. Where one is STDOUT then another is a reference to a File instance.
Thank you very much for your help zw963, now with the logs I generated, I was able to solve my last problems I had with my software. Now it able to build the crosstoolchain and temporary tools steps from the LFS, and the chroot work. Thanks so much !
Make one of your IOs you’re passing to the multi writer an IO::Memory. That’ll give you an in memory string representation of what was output via the command.