簡體   English   中英

os.system(cmd / all> file)給出了一個空文件,如果我直接在命令提示符下運行命令,則輸出到文本文件

[英]os.system (cmd /all >file) gives an empty file, if i run the command directly in the command prompt I am getting the output to text file

我正在嘗試使用“ vmrun list”命令查找所有正在運行的VM,並且我想在文本文件中輸出。

import os
os.system("C:\\Program\ Files\ (x86)\\VMware\VMware\ VIX\\vmrun /all >C:\\Users\\xyz\\Documents\\qw.txt ")

當我在命令提示符下運行相同的命令時,正在獲取命令提示符輸出的文件,但是當我在python中執行相同的操作時,我將得到一個空文件。 我該怎么做才能將輸出從python腳本輸出到文件?

您應該通過示例命令getoutput來查看子流程模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM