I guess what I'm looking for is the equivalent of Ruby's Process#spawn
In REPL:
>> pid = Process.spawn("ping www.google.com", :out => '/dev/null')
83210
>> <-- the process is running in the background and
control has been returned to the REPL
vineri, 22 ianuarie 2016, 22:06:01 UTC+1, Adrian Salceanu a scris:
>
> Hi,
>
> I'm hammering at a web app and I'm trying to setup functionality to
> monitor the file system for changes and restart/reload the server
> automatically so the changes are picked up (I'm using Mux which uses
> HttpServer).
>
> The approach I have in mind is:
>
> 1. have a startup script which is run from the command line, something
> like:
> $ julia -L startup.jl
>
> 2. the startup script launches the web app, which starts the web server.
> My intention was to run
> $ julia -L app.jl
> as a command inside startup.jl, detached, and have the startup.jl script
> get back control, with app.jl running detached in the background.
>
> 3. once startup.jl gets back control, it begins monitoring the file system
> and when changes are detected, kills the app and relaunches it.
>
> That was the theory. Now, I might be missing something but I can't find a
> way to detach the command I'm running and get control back to the startup
> script. And I tried a lot of things!
>
> ===
>
> I'm providing simpler example using "ping", which also run indefinitely,
> similar to the web server.
>
> julia> run(detach(`ping "www.google.com"`)) # the command is detached and
> continues to run after the julia REPL is closed, but at this point the REPL
> does not get control, there's no cursor available in the REPL
> PING www.google.com (173.194.45.82): 56 data bytes
> 64 bytes from 173.194.45.82: icmp_seq=0 ttl=54 time=30.138 ms
> 64 bytes from 173.194.45.82: icmp_seq=1 ttl=54 time=30.417 ms
> ... more output ...
> 64 bytes from 173.194.45.82: icmp_seq=7 ttl=54 time=30.486 ms
> 64 bytes from 173.194.45.82: icmp_seq=8 ttl=54 time=30.173 ms
> ^CERROR: InterruptException:
> <---- here I press Ctrl+C and only now the REPL gets back
> the cursor, with the command still running in the background
>
> ===
>
> Also, related to this, passing "&" into the command to detach does not
> work as expected, the "&" is interpreted as argument of the command. Not
> sure if this would help anyway to return control to the startup.jl script?
>
> julia> run(detach(`ping "www.google.com" &`));
> usage: ping [-AaDdfnoQqRrv] [-b boundif] [-c count] [-G sweepmaxsize]
> [-g sweepminsize] [-h sweepincrsize] [-i wait] [−k
> trafficclass]
> [-l preload] [-M mask | time] [-m ttl] [-p pattern]
> [-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z
> tos]
> host
> ping [-AaDdfLnoQqRrv] [-b boundif] [-c count] [-I iface] [-i wait]
> [−k trafficclass] [-l preload] [-M mask | time] [-m ttl] [-p
> pattern] [-S src_addr]
> [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
> [-z tos] mcast-group
> ERROR: failed process: Process(`ping www.google.com &`,
> ProcessExited(64)) [64]
> in run at /usr/local/Cellar/julia/0.4.2/lib/julia/sys.dylib
>
> ===
>
> Thanks
>