This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tsani's profile picture

Collecting Output of a Child Program

Started by tsani, 03 March 2013 - 06:07 AM
tsani #1
Posted 03 March 2013 - 07:07 AM
It's possible, in two different ways, to execute a program from within another, namely with os.run and shell.run, but it doesn't seem possible to collect the output of the child program in the parent program. The context of this question is that I'm making a simple program using rednet that will execute whatever is sent to it and reply with the output of the command.
Lyqyd #2
Posted 03 March 2013 - 08:53 AM
Split into new topic.

You can run the code manually using loadstring(), which is what os.run uses. You should be able to gather the return values that way.
immibis #3
Posted 03 March 2013 - 02:45 PM
Split into new topic.

You can run the code manually using loadstring(), which is what os.run uses. You should be able to gather the return values that way.
I think he wanted to get the text the program prints.

You can replace print and/or write with your own functions that send the text over rednet instead of printing it, then run the program (and then set them back to the normal functions, if you want to be able to use the computer normally as well).

If you're just trying to use a computer over a network, try using nsh.
tsani #4
Posted 04 March 2013 - 10:18 AM
You can replace print and/or write with your own functions that send the text over rednet instead of printing it, then run the program (and then set them back to the normal functions, if you want to be able to use the computer normally as well).

If you're just trying to use a computer over a network, try using nsh.

I was hoping maybe for a way to avoid having to temporarily overwrite print or write, but if it's what I have to do, I can do it. In this case though, I think using nsh is a better option; thanks for letting me know about it
bjornir90 #5
Posted 04 March 2013 - 09:19 PM
Or, for your general knowing, you can take the variables of a child program by putting them in a file, then read this file with the mother program.
LancerX #6
Posted 05 March 2013 - 05:35 AM
Just wondering, can you pass a table as an os event parameter? Seems like you could create a decoupled "pipe" by invoking the child program then polling for the event with a table{} parm…