1
に呼び出されたときにファイルに私はサブプロセスを開き、ファイルへの出力にそれを伝えたときにそれが動作する理由誰も私に説明することができますしないでください。Pythonのサブプロセス出力ループ
currentSharePath = '\\\Path1'
p = subprocess.Popen([r'powershell.exe',
'-ExecutionPolicy',
'Bypass',
os.path.dirname(os.path.abspath(__file__))+'\subFoldersClassifier.ps1',
'-sharePath',
currentSharePath,
'2>$null',
'| Out-File -encoding utf8 -append classified_subFolders.txt'],
stdout=sys.stdout)
p.communicate()
しかし、ときに私が呼んでそれは、ループ内での出力は、ファイルの代わりに私の端末に示されている:
with open('found_shares_cleaned.txt') as f:
content = f.readlines()
for currentSharePath in content:
p = subprocess.Popen([r'powershell.exe',
'-ExecutionPolicy',
'Bypass',
os.path.dirname(os.path.abspath(__file__))+'\subFoldersClassifier.ps1',
'-sharePath',
currentSharePath,
'2>$null',
'| Out-File -encoding utf8 -append classified_subFolders.txt'],
stdout=sys.stdout)
p.communicate()
は、事前にありがとう
はありがとうを!それは完璧に動作します –
受け入れていただきありがとうございます。もう別のupvoteの価値がある:) –