Piping between Python and RubyCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to write a switch statement in RubyDifference between __str__ and __repr__?Does Python have a string 'contains' substring method?

Does the Haste spell's hasted action allow you to make multiple unarmed strikes? Or none at all?

QgsGeometry.length() giving wrong result?

What's the relationship betweeen MS-DOS and XENIX?

What is the spellcasting ability of a Barbarian Totem Warrior?

Is there any official ruling on how characters go from 0th to 1st level in a class?

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

What is a "soap"?

100 Years of GCHQ - A quick afternoon puzzle!

When does The Truman Show take place?

Why do we use low resistance cables to minimize power losses?

How do I pass a "list of lists" as the argument to a function of the form F[x,y]?

Is this bar slide trick shown on Cheers real or a visual effect?

Duplicate and slide edge (rip from boundary)

Is there a word for returning to unpreparedness?

Figure with one caption below and one caption/legend on the side

What is the question mark?

What allows us to use imaginary numbers?

Doesn't the speed of light limit imply the same electron can be annihilated twice?

What modifiers are added to the attack and damage rolls of this unique longbow from Waterdeep: Dragon Heist?

How does the Moon's gravity affect Earth's oceans despite Earth's stronger gravitational pull?

Will some rockets really collapse under their own weight?

Will Force.com stop working on salesforce Lightning?

May the tower use the runway while an emergency aircraft is inbound?

What should I do with the stock I own if I anticipate there will be a recession?



Piping between Python and Ruby


Calling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to write a switch statement in RubyDifference between __str__ and __repr__?Does Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am writing a code which can send data between a Python and a Ruby script using a "pipeline" but can not get it to work. Any recommendations or alternative ways?



I have written simple scripts to get it working and build upon them. The objective is to integrate the "pipeline" functionality in a project. In the project, the Python script is to send a .txt file to the Ruby script, which will extract parameter values and store them in respective arrays. I then want to send the arrays back to the Python script.



The simple scripts i have made so far are inspired by https://www.decalage.info/python/ruby_bridge. When running, it continues without stopping and does not produce any results. The goal is to send the integer 6 to the Ruby script where 5 is added, and send the sum back to the Python script. When aborting with ctrl + c, the following is written:



File "./com_ruby.py", line 33, in <module>
sss = slave.stdout.readline().rstrip()


My Python script:



from subprocess import Popen, PIPE, STDOUT

print('launching slave process...')
slave = Popen(['ruby', 'provar.rb'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)

while True:

num = bytes([6])
slave.stdin.write(num)
# result will be a list of lines:
result = []
# read slave output line by line, until we reach "[end]"
while True:
# check if slave has terminated:
if slave.poll() is not None:
print('slave has terminated.')
exit()
# read one line, remove newline chars and trailing spaces:
sss = slave.stdout.readline().rstrip()
print('line: ', sss)
if sss == '[end]':
break
result.append(sss)
print('result:')
print('n'.join(result))


My Ruby script:



while cmd = STDIN.gets

cmd.chop!

cmd = cmd + 5

cmd.to_s
print eval(cmd),"n"
# append [end] so that master knows it's the last line:
print "[end]n"
# flush stdout to avoid buffering issues:
STDOUT.flush

end


Is there any better yet simple way to do the "piping" of data between the two scripts?










share|improve this question
























  • Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

    – dreftymac
    Apr 2 at 20:25

















1















I am writing a code which can send data between a Python and a Ruby script using a "pipeline" but can not get it to work. Any recommendations or alternative ways?



I have written simple scripts to get it working and build upon them. The objective is to integrate the "pipeline" functionality in a project. In the project, the Python script is to send a .txt file to the Ruby script, which will extract parameter values and store them in respective arrays. I then want to send the arrays back to the Python script.



The simple scripts i have made so far are inspired by https://www.decalage.info/python/ruby_bridge. When running, it continues without stopping and does not produce any results. The goal is to send the integer 6 to the Ruby script where 5 is added, and send the sum back to the Python script. When aborting with ctrl + c, the following is written:



File "./com_ruby.py", line 33, in <module>
sss = slave.stdout.readline().rstrip()


My Python script:



from subprocess import Popen, PIPE, STDOUT

print('launching slave process...')
slave = Popen(['ruby', 'provar.rb'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)

while True:

num = bytes([6])
slave.stdin.write(num)
# result will be a list of lines:
result = []
# read slave output line by line, until we reach "[end]"
while True:
# check if slave has terminated:
if slave.poll() is not None:
print('slave has terminated.')
exit()
# read one line, remove newline chars and trailing spaces:
sss = slave.stdout.readline().rstrip()
print('line: ', sss)
if sss == '[end]':
break
result.append(sss)
print('result:')
print('n'.join(result))


My Ruby script:



while cmd = STDIN.gets

cmd.chop!

cmd = cmd + 5

cmd.to_s
print eval(cmd),"n"
# append [end] so that master knows it's the last line:
print "[end]n"
# flush stdout to avoid buffering issues:
STDOUT.flush

end


Is there any better yet simple way to do the "piping" of data between the two scripts?










share|improve this question
























  • Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

    – dreftymac
    Apr 2 at 20:25













1












1








1








I am writing a code which can send data between a Python and a Ruby script using a "pipeline" but can not get it to work. Any recommendations or alternative ways?



I have written simple scripts to get it working and build upon them. The objective is to integrate the "pipeline" functionality in a project. In the project, the Python script is to send a .txt file to the Ruby script, which will extract parameter values and store them in respective arrays. I then want to send the arrays back to the Python script.



The simple scripts i have made so far are inspired by https://www.decalage.info/python/ruby_bridge. When running, it continues without stopping and does not produce any results. The goal is to send the integer 6 to the Ruby script where 5 is added, and send the sum back to the Python script. When aborting with ctrl + c, the following is written:



File "./com_ruby.py", line 33, in <module>
sss = slave.stdout.readline().rstrip()


My Python script:



from subprocess import Popen, PIPE, STDOUT

print('launching slave process...')
slave = Popen(['ruby', 'provar.rb'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)

while True:

num = bytes([6])
slave.stdin.write(num)
# result will be a list of lines:
result = []
# read slave output line by line, until we reach "[end]"
while True:
# check if slave has terminated:
if slave.poll() is not None:
print('slave has terminated.')
exit()
# read one line, remove newline chars and trailing spaces:
sss = slave.stdout.readline().rstrip()
print('line: ', sss)
if sss == '[end]':
break
result.append(sss)
print('result:')
print('n'.join(result))


My Ruby script:



while cmd = STDIN.gets

cmd.chop!

cmd = cmd + 5

cmd.to_s
print eval(cmd),"n"
# append [end] so that master knows it's the last line:
print "[end]n"
# flush stdout to avoid buffering issues:
STDOUT.flush

end


Is there any better yet simple way to do the "piping" of data between the two scripts?










share|improve this question














I am writing a code which can send data between a Python and a Ruby script using a "pipeline" but can not get it to work. Any recommendations or alternative ways?



I have written simple scripts to get it working and build upon them. The objective is to integrate the "pipeline" functionality in a project. In the project, the Python script is to send a .txt file to the Ruby script, which will extract parameter values and store them in respective arrays. I then want to send the arrays back to the Python script.



The simple scripts i have made so far are inspired by https://www.decalage.info/python/ruby_bridge. When running, it continues without stopping and does not produce any results. The goal is to send the integer 6 to the Ruby script where 5 is added, and send the sum back to the Python script. When aborting with ctrl + c, the following is written:



File "./com_ruby.py", line 33, in <module>
sss = slave.stdout.readline().rstrip()


My Python script:



from subprocess import Popen, PIPE, STDOUT

print('launching slave process...')
slave = Popen(['ruby', 'provar.rb'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)

while True:

num = bytes([6])
slave.stdin.write(num)
# result will be a list of lines:
result = []
# read slave output line by line, until we reach "[end]"
while True:
# check if slave has terminated:
if slave.poll() is not None:
print('slave has terminated.')
exit()
# read one line, remove newline chars and trailing spaces:
sss = slave.stdout.readline().rstrip()
print('line: ', sss)
if sss == '[end]':
break
result.append(sss)
print('result:')
print('n'.join(result))


My Ruby script:



while cmd = STDIN.gets

cmd.chop!

cmd = cmd + 5

cmd.to_s
print eval(cmd),"n"
# append [end] so that master knows it's the last line:
print "[end]n"
# flush stdout to avoid buffering issues:
STDOUT.flush

end


Is there any better yet simple way to do the "piping" of data between the two scripts?







python ruby python-3.x pipe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 12:34









putin putoutputin putout

61 bronze badge




61 bronze badge















  • Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

    – dreftymac
    Apr 2 at 20:25

















  • Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

    – dreftymac
    Apr 2 at 20:25
















Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

– dreftymac
Apr 2 at 20:25





Have you considered simply using a predictable file path to store data, and have python and ruby both read from and write to the same data file?

– dreftymac
Apr 2 at 20:25












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377323%2fpiping-between-python-and-ruby%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377323%2fpiping-between-python-and-ruby%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript