2011年10月14日 星期五

eval exec system

eval :
exec : execute system command




system 與 exec 都是用來執行系統指令的 function,

其中的差別是 system會回傳訊息,而exec不會。

比如: my $aaa = system(hostname);

$aaa 的數值會是 0

而 my $aaa = system(hostnam);

$aaa 的數值會是 -1,表示這個動作不成功。

不過別讓 exec 執行在程式的前面,否則它後面的程式似乎不會執行。

那我如果要取值的話,最好是用 `hostname`; 比較好,才能讓值給與變數。

再來探討 background 背景執行,我想要讓程式裡再執行一個背景作業,

用 `xxx &`; 的話就算是加了 & 它還是會等執行完再進行下一行,所以不是我要的,


更多内容 http://ssorc.tw/rewrite.php/read-1031.html#ixzz1aow4c35Y


exec()和system()的分別
 exec(PROGRAM);
 $result = system(PROGRAM); 
Both Perl's exec() function and system() function execute a system shell command. The big difference is that system() creates a fork process and waits to see if the command succeeds or fails - returning a value. exec() does not return anything, it simply executes the command. Neither of these commands should be used to capture the output of a system call. If your goal is to capture output, you should use the backtick operator:
 $result = `PROGRAM`; 

沒有留言:

張貼留言