12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 34: System Utilities 309in in and out. If execution of the command is successful, pid contains the process IDof the subprocess. Otherwise, pid is −1.For example,[in, out, pid] = popen2 ("sort", "-nr");fputs (in, "these\nare\nsome\nstrings\n");fclose (in);while (isstr (s = fgets (out)))fputs (stdout, s);endwhilefclose (out);⊣ are⊣ some⊣ strings⊣ theseEXEC PATHBuilt-in VariableThe variable EXEC_PATH is a colon separated list of directories to search when executingexternal programs. Its initial value is taken from the environment variableOCTAVE_EXEC_PATH (if it exists) or PATH, but that value can be overridden by thecommand line argument --exec-path PATH, or by setting the value of EXEC_PATH ina startup script. If the value of EXEC_PATH begins (ends) with a colon, the directoriesoctave-home/libexec/octave/site/exec/archoctave-home/libexec/octave/version/exec/archare prepended (appended) to EXEC_PATH, where octave-home is the top-level directorywhere all of <strong>Octave</strong> is installed (the default value is ‘/usr/local’). If you don’t specifya value for EXEC_PATH explicitly, these special directories are prepended to your shellpath.In most cases, the following functions simply decode their arguments and make thecorresponding Unix system calls. For a complete example of how they can be used, look atthe definition of the function popen2.[pid, msg] = fork ()Create a copy of the current process.Fork can return one of the following values:Built-in Function> 0 You are in the parent process. The value returned from fork is theprocess id of the child process. You should probably arrange to wait forany child processes to exit.0 You are in the child process. You can call exec to start another process.If that fails, you should probably call exit.< 0 The call to fork failed for some reason. You must take evasive action. Asystem dependent error message will be waiting in msg.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!