藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


在使用system()中的一個疑問?

我在使用system函數中時,
在一些小程序中(十幾行代碼),使用 system(" command「);可以執行。
可是在較大的程序中,使用system(" command「);該代碼不執行,
需使用
  str="command";
   system(str);
方式時才可以運行。
本人很菜,搞不明白,請各位指點一二。 :roll:

在使用system()中的一個疑問?

可是在較大的程序中,使用system(" command「);該代碼不執行,


這種情況應該不會發生的。

在使用system()中的一個疑問?

都可以吧
另外使用system時會先啟動一個shell
然後由那個shell執行你的命令
所以對資源使用比較多

你可以使用 for exec代替

在使用system()中的一個疑問?

我覺得這個情況確實沒有道理 :)


另外,問一個題外話,system()的返回值是該函數捕獲command的返回值呢,還是該函數捕獲SHELL的返回值(SHELL捕獲command的返回值)呢!?

在使用system()中的一個疑問?

2種情況是一樣的

在使用system()中的一個疑問?

在使用system()中的一個疑問?

發生這種錯誤一定有原因的,但肯定與system函數無關!首先檢查一下內存分配情況

在使用system()中的一個疑問?

system最終由fork+exec*實現.如下對於return values的說明來自於hp-11,可以參考一下。

If command is null, system() returns non-zero.
If command is not null, system() returns the termination status of the  command language interpreter in the format specified by wait(2).  The termination status of the command language interpreter is as specified for sh-posix(1), except that if some error prevents the command language interpreter from executing after the child process is  created, the return value from system() is as if the command language  interpreter had terminated using _exit(127).  If a child process  cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() returns -1 and sets    errno to indicate the error.

在使用system()中的一個疑問?

我是個新手,我的這個程序,是結合newt圖形函數,好像這個函數是基於堆戔操作的,如果是內存分配問題的話,是否與這個函數有關?
謝謝

在使用system()中的一個疑問?

應該是
因為產生一個shel是很浪費內存的

另外看看你系統的man
多數平台上都是返回一個shell然後再執行命令

在使用system()中的一個疑問?

你可以使用fork exec代替
這樣需要的stack會少點



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com