[julia-users] Re: Getting the name of the running program
If with name of the program you mean the name of the file where the function is defined println(@__FILE__) makes the job. On Friday, April 8, 2016 at 10:53:14 AM UTC+2, Ferran Mazzanti wrote: > > Hi folks, > > probably a most stupid question here :) Is there a way to get a string > with the name of the Julia program one is running? > I ask because I usually write output files starting with a header stating > something like "# Results generated by the program " followed by the > program name. So how could I get the name of the program I'm running? > > Best regards and thanks, > > Ferran. >
[julia-users] Re: Getting the name of the running program
In addition to getting the current file via @__FILE__, in Julia 0.5 you can get the name of the currently running script (e.g. "foo.jl" when you run "julia foo.jl") via PROGRAM_FILE: https://github.com/JuliaLang/julia/pull/14114
[julia-users] Re: Getting the name of the running program
Hi, thanks for the tip, but in IJulia @__FILE__="" and nothings cames out from the println()... I'm running julia 0.4.5, so no 0.5 solution is useful here... Best, Ferran. On Friday, April 8, 2016 at 1:33:00 PM UTC+2, Andrea Pagnani wrote: > > If with name of the program you mean the name of the file where the > function is defined > > println(@__FILE__) > > makes the job. > > On Friday, April 8, 2016 at 10:53:14 AM UTC+2, Ferran Mazzanti wrote: >> >> Hi folks, >> >> probably a most stupid question here :) Is there a way to get a string >> with the name of the Julia program one is running? >> I ask because I usually write output files starting with a header stating >> something like "# Results generated by the program " followed by the >> program name. So how could I get the name of the program I'm running? >> >> Best regards and thanks, >> >> Ferran. >> >
Re: [julia-users] Re: Getting the name of the running program
You can use backtrace() for this, but interpreting the result is a little complicated. See the implementation of @showln in https://github.com/timholy/DebuggingUtilities.jl for some pointers. Best, --Tim On Monday, April 11, 2016 02:02:12 AM Ferran Mazzanti wrote: > Hi, > > thanks for the tip, but in IJulia @__FILE__="" and nothings cames out from > the println()... > I'm running julia 0.4.5, so no 0.5 solution is useful here... > > Best, > > Ferran. > > On Friday, April 8, 2016 at 1:33:00 PM UTC+2, Andrea Pagnani wrote: > > If with name of the program you mean the name of the file where the > > function is defined > > > > println(@__FILE__) > > > > makes the job. > > > > On Friday, April 8, 2016 at 10:53:14 AM UTC+2, Ferran Mazzanti wrote: > >> Hi folks, > >> > >> probably a most stupid question here :) Is there a way to get a string > >> with the name of the Julia program one is running? > >> I ask because I usually write output files starting with a header stating > >> something like "# Results generated by the program " followed by the > >> program name. So how could I get the name of the program I'm running? > >> > >> Best regards and thanks, > >> > >> Ferran.