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

Calling a command, and then getting the text it returns?

Started by NullSchritt, 05 May 2013 - 02:59 AM
NullSchritt #1
Posted 05 May 2013 - 04:59 AM
Hello, I am a total noob, so forgive me if this is a simple question, but how would I go about running a command, and then receiving it's text output, so I could display it on the screen?

I want to make a program that automatically dials 1 stargate to another on my server, by executing a command, the command then says back the status of the dialing process as it dials (normally when a person executes the command, it sends personal messages to them telling them the dailing status of the gate) [chevron 1 locked, chevron 2 locked, chevron 3 locked, dail attempt failed <reason>]

I was wondering how I would go about displaying each line of text on an attached monitor as it was sent back to the computer executing the command.

Really appreciate any advice, thanks!
Shnupbups #2
Posted 05 May 2013 - 05:01 AM

print(someFunction()) --# Make sure you define a function named someFunction first, or edit this!
BOOM! One-liner.
EDIT: Or if you want to keep the data after you print it:

local data = someFunction() --# Make sure you define a function named someFunction first, or edit this!
print(data)
--# Feel free to use the variable 'data' anywhere after this (though only within this program)
Bubba #3
Posted 05 May 2013 - 09:21 AM
In addition to Shnupbups response, you need to use a "return" in the function if you want to get some value from it.

local function getValue()
  --Do some stuff here...
  return "This is a value"
end

local value = getValue()
print(value) --Prints "This is a value"
Lyqyd #4
Posted 05 May 2013 - 12:26 PM
Not at all what was being asked, guys. He wants to handle these responses over time, not just once.

OP, we will need more details about your setup, but it sounds like you could either have the computer handling the stargate write it directly on a screen, or send the messages via rednet to the other computer.