Properly source ENV variables



I am trying to use Julia to automate an interface with a server running ROS. To do this I need to source some environment variables:


where the xxx’s are digits for IP addresses and port numbers.

If I run these commands in the terminal, I can thereafter run commands like rostopic list and receive the expected output.
Running ENV["ROS_MASTER"] = "" etc. in my script and then running run(`rostopic list`) errors out with “ERROR: Unable to communicate with master!” and a pipeline_error.
I also tried putting the export commands into my .bashrc and in my .juliarc.jl. These didn’t fix it either.
Is there something I am missing?



Does your script contain ENV["ROS_MASTER"] or ENV["ROS_MASTER_URI"]?


I use backticks - not sure how to get those to show up in markdown

Just keep adding more backticks around the string you want to code-quote until it’s right:

``run(`rostopic list`)``

(to do the above, prepend four spaces).

And yeah, I think @schmrlng is onto something.


I have tried setting all three variables in the script:

ENV["ROS_IP"] = ""

but otherwise do not use ENV.


Though this is not recommended (use it with causion), I shamelessly mention Shell.jl. If it is helpful, pls report bugs or errors in the package :slight_smile:

using Shell"""
rostopic list


I get an error: “could not spawn zsh /tmp/juliawGdwxK: no such file or directory”.
Calling"ls") throws the same error.
Oh, sorry. takes in a String, not a cmd. It works!


What do you get if you run(`env`)? That should print all of the current environment variables. I’m unable to duplicate your issue; if the environment variables show up as you would expect them in run(`env`) then I might double-check your ROS setup outside of julia.

 schmrlng@europa ~ julia
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation:
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.1 (2017-10-24 22:15 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu

julia> ENV["ROS_MASTER_URI"] = ""; ENV["ROS_IP"] = ""; ENV["ROS_HOSTNAME"] = ""

julia> run(`rostopic list`)

julia> ENV["ROS_MASTER_URI"] = "http://XXX.XXX.XXX.140:11311"; ENV["ROS_IP"] = "XXX.XXX.XXX.209"; ENV["ROS_HOSTNAME"] = "XXX.XXX.XXX.209"

julia> run(`rostopic list`)


You may try, shell="bash") because I default the shell to zsh…


Okay, so it works in the REPL and it works in a standalone script but some other things I am running ahead of that (curl commands) cause it to not work. Seems to be a problem that I introduce.
Sorry for the false alarm.
Thanks for everyone’s input.
Yeah, looks like I just needed a sleep(1) command. :frowning: