系统命令的含义仅包含路径名和-C标志

时间:2014-05-05 10:47:40

标签: python shell command

对不起,如果这是一个愚蠢的问题,但我是一个物理学家而不是程序员,所以请耐心等待。我正在使用GUI调试图像注册演示,以及出错的地方。该演示在最初编写的机器上运行良好,但该机器和我的机器都是Windows 7 64位机器。整个代码的具体细节或其目的确实不重要,我已将错误缩小到以下代码部分:

def targetConvert(self):
    self.targetExtHeader = '.'+self.targetText.GetValue().split('.')[-1]
    self.targetExtBinary = self.getBinaryFileExtension( self.targetExtHeader )

    self.targetFile = 'target_org'+self.targetExtHeader

    # split 4D data sets, currently available only when .par file format
    # is used
    if self.targetExtHeader == '.par' or self.targetExtHeader == '.PAR':
        self.logOutput.AppendText('Split target to multiple 3D images and store in tmp/ folder.\n')
        cmd = []
        cmd.append(self.lreg + ' -C ' + '\"'+self.targetText.GetValue()+'\"' + ' ' + '\"'+self.tmpFolder + self.targetFile+'\"')            

        print '\n\n\n'+cmd[0]+'\n\n\n'
        self.executeCommandList(cmd)
        ...

def executeCommandList(self, cmd):

    self.busyLabel.SetLabel(' Busy ')
    self.busyLabel.SetBackgroundColour('Red')
    self.Layout()
    self.Refresh()

    for i in range(0,len(cmd)):
        self.logOutput.AppendText( '\nCommand(s):\n' )
        self.logOutput.AppendText( cmd[i] )
        self.logOutput.AppendText( '\n\n' )
        self.process = subprocess.Popen( cmd[i], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
        while self.process.poll() is None:
            line = self.process.stdout.readline()
            self.logOutput.AppendText( line )

        # wait a second
        time.sleep(0.1)

    self.busyLabel.SetLabel('Ready')
    self.busyLabel.SetBackgroundColour(self.backgroundColorPanel)
    self.Layout()
    self.Refresh()

在executeCommandList中传递给cmd [i]系统的命令是:

"C:\Users\310079322.CODE1\Documents\Thesis\regDemo\\lreg\\lreg.exe" -C "C:\Users\310079322.CODE1\Documents\Thesis\regDemo\ParrecImgsForRegisration\WIP_SSh_DWI_FAST_SENSE_8_1.PAR" "C:\Users\310079322.CODE1\Documents\Thesis\regDemo\\tmp\\target_org.PAR"

Google无法向我解释此命令的用途是什么,但我认为它不起作用。我的直觉是它应该将 targetFile 复制到 self.tmpFolder ,但我不确定,因为源文件没有这个subprocess.open的东西在executeCommandList方法中看到了,但是,文件sourceConvert直接照顾它:

def sourceConvert(self):
    self.sourceExtHeader = '.'+self.sourceText.GetValue().split('.')[-1]
    self.sourceExtBinary = self.getBinaryFileExtension( self.sourceExtHeader )

    self.sourceFile = 'source'+self.sourceExtHeader
    self.logOutput.AppendText('Copy source T2 to tmp/ folder.\n')

    shutil.copyfile(self.sourceText.GetValue()[:-4] + self.sourceExtHeader, self.tmpFolder + self.sourceFile[:-4] + self.sourceExtHeader)

任何人都可以帮我解释一下这个问题,也就是说,通过executeCommand方法传递给shell的命令是什么,以及我遇到的实现问题可能是什么?

祝你好运, 的Mikael

1 个答案:

答案 0 :(得分:0)

您可以随时尝试询问lreg.exe本身;从Windows开始菜单运行cmd.exe,进入lreg.exe所在的文件夹,并使用-h参数运行它,如下所示:

cd \Users\310079322.CODE1\Documents\Thesis\regDemo\lreg [hit enter] lreg.exe -h

如果lreg.exe支持命令行帮助,您应该看到所有选项,其中包括-C选项;它不确定,但它通常值得一试。

-G。