Qt QProcess将字符串中的每个字母单独读取

Qt QProcess将字符串中的每个字母单独读取,qt,pyqt,mkdir,qprocess,pyqt5,Qt,Pyqt,Mkdir,Qprocess,Pyqt5,我正在尝试使用QProcess来运行mkdir命令(我正在使用linux)。该过程将在用户桌面上创建一个名为“output”的文件夹。代码如下所示: def mkOutput(): # get the user's environmental variables env = QtCore.QProcessEnvironment.systemEnvironment() proc = QtCore.QProcess() proc.setProcessEnvironme

我正在尝试使用
QProcess
来运行
mkdir
命令(我正在使用linux)。该过程将在用户桌面上创建一个名为“output”的文件夹。代码如下所示:

def mkOutput():
    # get the user's environmental variables
    env = QtCore.QProcessEnvironment.systemEnvironment()
    proc = QtCore.QProcess()
    proc.setProcessEnvironment(env)

    # find the HOME variable, append it to args
    HOME = env.value('HOME', defaultValue='./')
    args = "/Desktop/output/"

    args = HOME+args

    proc.setStandardOutputFile('out.txt')
    proc.setStandardErrorFile('err.txt')
    proc.start("mkdir", args)
    proc.waitForFinished()
out.txt为空,而err.txt读取:

/usr/bin/mkdir: cannot create directory ‘/’: File exists
/usr/bin/mkdir: cannot create directory ‘o’: File exists
/usr/bin/mkdir: cannot create directory ‘t’: File exists
/usr/bin/mkdir: cannot create directory ‘p’: File exists
/usr/bin/mkdir: cannot create directory ‘u’: File exists
/usr/bin/mkdir: cannot create directory ‘t’: File exists
/usr/bin/mkdir: cannot create directory ‘/’: File exists
出于某种原因,它试图对参数中的每个字母运行
mkdir
,而不是使用整个字符串本身。 我曾尝试使用str()在
args
变量上执行操作,但似乎没有任何效果。每次它只是在我运行程序的目录中创建多个文件夹。

在中,
args
应该是一个列表或元组。因为您传递的是一个字符串,所以PyQt将其转换为一个列表,使Qt接收字符串中每个字符的列表。要解决此问题,请将
args=“/Desktop/output/”
更改为
args=(“/Desktop/output/”)

顺便说一句,Python有一个for
mkdir()

谢谢!我将改为使用mkdir(),但我还有一些其他调用,其中也发生了同样的事情,所以很高兴知道这一点