(翻译)Phobos 2.029 P部 std.process

std.process           
            
Jump to: system execv execve execvp execvpe shell getenv
跳转: system execv execve execvp execvpe shell getenv
            
Authors:            
Walter Bright, Andrei Alexandrescu
            
int system(string command);
Execute command in a command shell.
在命令行执行命令command。
            
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).
如果command为null,同时找到了命令解释器,返回非零值,否则返回0;如果command不为null,出错返回-1,否则返回命令退出状态(它反过来标记命令执行过程的出错)。
            
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.
在Unix系统,该函数的调用机制有点不同(D程序可通过模块std.c.system访问),其返回与waitpid格式一样的代码,意味着C程序必顺用WEXITSTATUS宏来提取调用system的实际退出代码。D系统自动提取该退出状态。
            
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.
运行由pathname指定的程序,传递参数argv和环境envp给该程序,并返回退出状态。'p'版本会查找为该程序设置的系统变量。
            
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.
在命令行执行cmd命令并返回标准输出。如果该进程未能启动或因错误退出,则抛出异常。
            
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.
以字符串形式返回环境变量name,内部调用std.c.stdlib.getenv。

你可能感兴趣的:(C++,c,unix,C#,F#)