我一直在寻找一个解决方案,而不是在不断地遇到错误。你知道吗
try:
#create working dir if it doens't exist already
if not os.path.isdir(WORKINGDIR):
print '>>>mdkir ',WORKINGDIR
subprocess.Popen(['mkdir',WORKINGDIR]).wait()
print os.path.isdir(WORKINGDIR)
#create output csv file
outputCSVFile = WORKINGDIR+ '/'+'results.csv'
if not os.path.isfile(outputCSVFile):
print '>>> touch',outputCSVFile
subprocess.check_output(['touch',outputCSVFile])
{cd1}总是返回{cd3}:
touch: cannot touch `/nfs/iil/proj/mpgarch/archive_06/CommandsProfiling/fastScriptsOutput190916/results.csv': No such file or directory
当我使用subprocess.checkoutput
而不是subprocess.Popen().wait()
时,不会出现同样的错误。
我知道这个问题可以用很多方法来解决(比如使用os
方法来创建目录和文件),但是我对我的方法不起作用的原因很感兴趣。你知道吗
提前谢谢。你知道吗
编辑:正如一些人所建议的,问题可能在于程序在subprocess.Popen
之后继续过快,因此使用subprocess.checkoutput
解决问题,后者可能较慢(因为它必须等待输出)。但我仍然不清楚到底发生了什么,因为os.path.istdir
显示dir是在继续执行touch
的行之前创建的
我想你有文件权限问题。 它显示在您的NFS路径中。你已经在本地文件系统上试过了吗?你知道吗
无论如何,您应该避免将子进程用于简单的文件操作。你知道吗
要创建目录:
对于触摸:
相关问题 更多 >
编程相关推荐