Perl qx 函式



說明

此函式是使用反引號執行系統命令的替代方法。例如,qx(ls -l) 將使用 -l 命令列選項執行 UNIX ls 命令。您實際可以使用任何一組分隔符,而不僅僅是括號。

語法

下面是此函式的簡單語法 -

qx EXPR

返回值

此函式從執行的系統命令中返回該值。

示例

下面是顯示其基本用法的示例程式碼 -

#!/usr/bin/perl -w

# summarize disk usage for the /tmp directory
# and store the output of the command into the
# @output array.
@output = qx(du -s /tmp);

print "@output\n";

執行上述程式碼時,會產生以下結果 -

176     /tmp
perl_function_references.htm
廣告
© . All rights reserved.