Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';使用python subprocess.call的trm-r目录_Python_Shell_Exception_Subprocess_Rm - Fatal编程技术网

Can';使用python subprocess.call的trm-r目录

Can';使用python subprocess.call的trm-r目录,python,shell,exception,subprocess,rm,Python,Shell,Exception,Subprocess,Rm,嗯,我需要从python中删除一些巨大的临时目录,而我似乎无法使用rm-r。我工作的时候觉得有一个大数据集(在s3上),我没有足够的磁盘空间来存放它们 我通常从python调用命令的方式是 import subprocess subprocess.call('rm','-r','/home/nathan/emptytest') 这给了我 Traceback (most recent call last): File "<stdin>", line 1, in <modul

嗯,我需要从python中删除一些巨大的临时目录,而我似乎无法使用rm-r。我工作的时候觉得有一个大数据集(在s3上),我没有足够的磁盘空间来存放它们

我通常从python调用命令的方式是

import subprocess
subprocess.call('rm','-r','/home/nathan/emptytest')
这给了我

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 629, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/lib/python2.7/subprocess.py”,第493行,在调用中
返回Popen(*popenargs,**kwargs)。等待()
文件“/usr/lib/python2.7/subprocess.py”,第629行,在__
raise TypeError(“bufsize必须是整数”)
TypeError:bufsize必须是整数

这是怎么回事?

你说得不对。第一个参数应该是一个列表:

import subprocess
subprocess.call(['rm','-r','/home/nathan/emptytest'])

您也可能只是想尝试使用

您称它为错误的方式。第一个参数应该是一个列表:

import subprocess
subprocess.call(['rm','-r','/home/nathan/emptytest'])

根据文档,您可能还想尝试使用

  >> In [3]: subprocess.call?
  Type:           function
  Base Class:     <type 'function'>
  String Form:    <function call at 0x01AE79F0>
  Namespace:      Interactive
  File:           c:\python26\lib\subprocess.py
  Definition:     subprocess.call(*popenargs, **kwargs)
  Docstring:
      Run command with arguments.  Wait for command to complete, then
  return the returncode attribute.
  The arguments are the same as for the Popen constructor.  Example:
  retcode = call(["ls", "-l"])

根据文件,

  >> In [3]: subprocess.call?
  Type:           function
  Base Class:     <type 'function'>
  String Form:    <function call at 0x01AE79F0>
  Namespace:      Interactive
  File:           c:\python26\lib\subprocess.py
  Definition:     subprocess.call(*popenargs, **kwargs)
  Docstring:
      Run command with arguments.  Wait for command to complete, then
  return the returncode attribute.
  The arguments are the same as for the Popen constructor.  Example:
  retcode = call(["ls", "-l"])

是的,我认为shutil.rmtree是我真正想要的。我在一个try-except块中尝试了这个,但失败了。原因是什么?它确实像你说的那样工作。是的,我认为shutil.rmtree是我真正想要的。我在一个试块中尝试了这个,但失败了。原因是什么?它确实像你说的那样起作用了。