Hardware Reference
In-Depth Information
Next, you must specify the command to run. This is done with
begin()
:
Process.begin(command);
The
command
parameter is a text representation of the command or program
to execute; for example,
cat
,
ls
,
curl
, and such. To add one or more parameters,
use
addParameter()
:
Process.addParameter(param);
This function takes one parameter, a string with the parameter to add:
Process p; // Create a Process class
p.begin("cat"); // Prepare a program
p.addParameter("/proc/cpuinfo"); // Add a parameter
The i nal step is to run the application with the required parameters, which
is done with
run()
:
Process.run();
This function does not take any parameters and executes the program. This is a
blocking function; the function does not return until the Linux program i nishes.
If you run a program that will not exit by itself, your sketch will freeze and will
not continue. To run a program that does not exit, use
runAsynchronously()
:
Process.runAsynchronously();
This function does not take any parameters, executes the Linux application,
and returns immediately. The application may or may not be running. To check
the status of a program, use
running()
:
result = Process.running();
This function does not take any parameters and returns a
boolean
:
true
if
the application is still running and
false
if it has terminated.
When an application terminates, it often returns a
return code,
which is a numeri-
cal value that can give information about the return conditions. (For example, curl
will return 2 if the application failed to initialize, 3 if the URL was malformed,
and 7 if it failed to connect to the host.) To get the return code, use
exitValue()
:
result = Process.exitValue();
This function returns an
unsigned int
: the return code of the Linux applica-
tion. It is not necessary to read the return code for every application. You can
call this only when it's needed.
Some applications require text input to operate correctly, asking the user for
certain parameters before executing actions. Before asking information from
the user, applications normally display text information. To help exchange data,
read-and-write functions are available.
To read data from a process, use
read()
:
data = Process.read();
Search WWH ::
Custom Search