0
私はPythonスクリプトの中でbash "test"コマンドを実行したいと思います。Pythonスクリプトの中でbash testコマンドの結果を確認する方法は?
たとえば、bash販売スクリプトでは、これは次のように簡単に実行できます。 ! #/ binにPythonスクリプト、私は次の方法を試してみてくださいかもしれないと思うと/ bashの
if ! test -s ${file}; then
echo "${file} does not have a positive size. "
# Do some processing..
fi
:
#!/usr/bin/python
import subrocess
try:
subprocess.check_call("test -s " + file, shell=True)
except:
print file + " does not have a positive size. "
# Do some process
は、上記のアプローチ良い方法ですか?そうでない場合は、適切な方法を提案してください。