cannot run a ruby script from a python script.

Cameron Simpson cs at zip.com.au
Thu Sep 25 02:44:28 CEST 2014


On 24Sep2014 16:57, Shawn Bright <shawn at skrite.net> wrote:
>i have a linux computer that i use to run a GUI (wxGTK) program. In this 
program, there is a call to run an external ruby script.
>
>command = "ruby run_my_command.rb &"
>os.system(command)
>
>however, when it runs, i get this in the terminal
>sh: 1: ruby: not found
>
>i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine.
>
>also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup.
>
>Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import.

For your edification: modify your command to be this:

   command = "which ruby; echo $PATH; ruby run_my_command.rb &"

and see if the output says what you expect.

 From the behaviour you describe I would expect that the GUI program, when it 
fails, is not being invoked from your command line but from some menu or 
suchlike. Further, I would guess that the invoking program (window manager, 
whatever) does not have ruby in its $PATH. This same effect obtains when you 
use the full path to ruby (usually a bad idea because your script may not work 
on another system where ruby is somewhere different) because like $PATH, the 
ruby search path also lacks the directories where the modules reside.

When you run it from your command prompt or from the python interpreter your 
environment is already set up with this extra information.

Cheers,
Cameron Simpson <cs at zip.com.au>

C makes it easy for you to shoot yourself in the foot.  C++ makes that
harder, but when you do, it blows away your whole leg.
- Bjarne Stroustrup



More information about the Python-list mailing list