Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to return value from ruby script and read that value inside c or shell script?

How can we return value from ruby script?

#!/usr/bin/env ruby

a = "test"
a

How can we access the value of 'a' in Ubuntu terminal or java or c?

like image 908
krunal shah Avatar asked Jan 21 '15 19:01

krunal shah


2 Answers

print your variable within ruby/python script, it can then be read from a shell script by example :

#!/bin/bash
ruby_var=$(ruby myrubyscript.rb)
python_var=$(python mypythonscript.py)

echo "$ruby_var"
echo "$python_var"

take care your ruby/python script only print this variable ( there are more complicated ways with named pipes by example for more interaction ).

like image 56
philippe lhardy Avatar answered Oct 22 '22 07:10

philippe lhardy


If the value is an integer between 0 and 255, you can use the exit status

$ ruby -e 'var=42; exit var'
$ val=$?
$ echo $val
42
like image 23
glenn jackman Avatar answered Oct 22 '22 05:10

glenn jackman