【问题标题】:Meaning of command to system consisting of only pathnames and -C flag仅包含路径名和 -C 标志的系统命令的含义
【发布时间】:2014-05-05 10:47:40
【问题描述】:

对不起,如果这是一个愚蠢的问题,但我是物理学家而不是程序员,所以请多多包涵。我正在调试一个带有 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,但我不确定,因为对于源文件,在使用了 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-method传递给shell的命令应该做什么,我遇到的实现可能有什么问题?

最好的问候, 迈克尔

【问题讨论】:

  • 你正在运行lreg.exe。我们不知道这个程序是什么,但这样的代码看起来是正确的。

标签: python shell command


【解决方案1】:

您可以随时尝试询问 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.

【讨论】:

  • 谢谢你,至少有一个问题!不知何故,我错过了第一个路径是一个 .exe 文件,只是假设它是其中一个数据文件,这就解释了为什么我不能告诉该命令应该运行一个程序。
  • 命令行越长 - 越难找到发生了什么 :) 刚刚注意到 -C 选项语法 - 这意味着应该有一些其他选项。
猜你喜欢
  • 2015-11-14
  • 2011-02-19
  • 1970-01-01
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 2011-01-27
  • 2014-12-13
  • 1970-01-01
相关资源
最近更新 更多