LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1688|回复: 4

谁能举个例子说明一下system和exec的区别嘛?

[复制链接]
发表于 2004-5-7 10:37:29 | 显示全部楼层 |阅读模式
rt
发表于 2004-5-7 12:48:32 | 显示全部楼层
主要不同在它们的返回值上:
  1. system (LIST)
  2. Category: Process
  3. Return Value: SCALAR, the exit code of the system command that was executed.
  4. Definition: Executes LIST as an operating system call. The process to execute this command is forked and the script waits for the child process to return.
  5. Note
  6.     To capture the output from a system call use a back-quoted string instead of system().
  7. system("ls -F /var > /tmp/t.tmp");
复制代码
  1. exec (LIST)
  2. Category: Process
  3. Return Value: None.
  4. Definition: This fuNCtion passes control from the script to an external system command. There is no return from this call. Note that system() calls external commands and does return.
  5. exec("cat /etc/motd");
复制代码
发表于 2004-5-7 20:49:49 | 显示全部楼层
exec会用新程序替代本进程
发表于 2004-5-8 08:29:21 | 显示全部楼层
最初由 libinary 发表
exec会用新程序替代本进程

哦?是吗,那exec后面的代码就无用了?
发表于 2004-5-8 20:02:53 | 显示全部楼层
最初由 tx-cary 发表
哦?是吗,那exec后面的代码就无用了?

除非exec调用出错,否则后面的代码不会执行,
所以一般exec后面的代码都是错误处理
另外,你应该看看fork,一般exec都和fork一起用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表