D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Sun Apr 19 16:54:18 2009

# std.process

Authors:
Walter Bright, Andrei Alexandrescu

int system(string command);
  Execute command in a command shell.

  Returns:
  If command is null, returns nonzero if the command interpreter is found, and zero otherwise. If command is not null, returns -1 on error, or the exit status of command (which may in turn signal an error in command's execution).

  Note:
  On Unix systems, the homonym C function (which is accessible to D programs as std.c.system) returns a code in the same format as waitpid, meaning that C programs must use the WEXITSTATUS macro to extract the actual exit code from the system call. D's system automatically extracts the exit status.

int execv(in string pathname, in immutable(char)[][] argv);
int execve(in string pathname, in immutable(char)[][] argv, in immutable(char)[][] envp);
int execvp(in string pathname, in immutable(char)[][] argv);
int execvpe(in string pathname, in immutable(char)[][] argv, in immutable(char)[][] envp);
  Execute program specified by pathname, passing it the arguments (argv) and the environment (envp), returning the exit status. The 'p' versions of exec search the PATH environment variable setting for the program.

string shell(string cmd);
  Runs cmd in a shell and returns its standard output. If the process could not be started or exits with an error code, throws an exception.

  Example:

         auto tempFilename = chomp(shell("mcookie"));
         auto f = enforce(fopen(tempFilename), "w");
         scope(exit)
         {
             fclose(f) == 0 || assert(false);
             system("rm " ~ tempFilename);
         }
         ... use f ...

string getenv(in char[] name);
  Gets the value of environment variable name as a string. Calls std.c.stdlib.getenv internally.

Copyright © 1999-2009 by Digital Mars, All Rights Reserved | Page generated by Ddoc.