共計 719 個字符,預計需要花費 2 分鐘才能閱讀完成。
要調用 Perl 腳本,可以使用 Python 的 subprocess
模塊。以下是一個調用 Perl 腳本的示例代碼:
import subprocess
# 要調用的 Perl 腳本路徑
perl_script = '/path/to/perl/script.pl'
# 調用 Perl 腳本并傳遞參數
args = ['arg1', 'arg2', 'arg3']
process = subprocess.Popen(['perl', perl_script] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# 輸出 Perl 腳本的執行結果
print(output.decode('utf-8'))
print(error.decode('utf-8'))
在上面的示例中,我們首先指定要調用的 Perl 腳本的路徑。然后,我們可以使用 subprocess.Popen
函數來啟動一個新的進程,將 perl
命令和腳本路徑以及參數作為參數傳遞給它。stdout=subprocess.PIPE
和 stderr=subprocess.PIPE
參數用于捕獲腳本的輸出和錯誤信息。
最后,我們可以使用 communicate
方法獲取腳本的輸出和錯誤信息,并使用 decode
方法將字節數據轉換為字符串數據,以便輸出到控制臺。
請確保在調用 Perl 腳本之前正確安裝了 Perl 解釋器,并將腳本路徑替換為您實際的 Perl 腳本路徑。
丸趣 TV 網 – 提供最優質的資源集合!
正文完