Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run external program from Julia and wait until it finishes, then read its output

Tags:

julia

I'm trying to execute external program from Julia via run, then wait until it finishes and store its output into a variable.

The only solution I came up with is this:

callback = function(data)
  print(data)
end

open(`minizinc com.mzn com.dzn`) do f
  x = readall(f)
  callback(x)
end

The problem is that I do not want to use callbacks.

Is there any way, how to wait until the process is finished and then continue in executing?

Thanks in advance

like image 725
mrtn Avatar asked Mar 13 '23 08:03

mrtn


1 Answers

You can just call readall (or readstring on Julia master) on the command object:

julia> readall(`echo Hello`)
"Hello\n"
like image 53
StefanKarpinski Avatar answered Apr 26 '23 23:04

StefanKarpinski