这是为我正在研究的脚本。它应该运行以下循环的.exe文件。 (顺便说一下,不确定它是否可见,而是对EL('90','52.6223',...)在循环外部,其余的嵌套环在循环之外),我不确定订购是否正确或没有什么。同样,当.exe文件运行时,它会吐出一些内容,我需要在屏幕上打印一条一行(因此,您可以看到Aspecificlinfe = ...)。任何有用的答案都很棒!

for el in ('90.','52.62263.','26.5651.','10.8123.'):

    if el == '90.':
        z = ('0.')
    elif el == '52.62263.':
        z = ('0.', '72.', '144.', '216.', '288.')
    elif el == '26.5651':
        z = ('324.', '36.', '108.', '180.', '252.')
    else el == '10.8123':
        z = ('288.', '0.', '72.', '144.', '216.')

        for az in z:

            comstring = os.path.join('Path where .exe file is')
            comstring = os.path.normpath(comstring) 
            comstring = '"' + comstring + '"'

            comstringfull = comstring + ' -el ' + str(el) + ' -n ' + str(z)

            print 'The python program is running this command with the shell:'
            print comstring + '\n'

            process = Popen(comstring,shell=True,stderr=STDOUT,stdout=PIPE)
            outputstring = myprocesscommunicate()

            print 'The command shell returned the following back to python:'
            print outputstring[0]

                AspecificLine=linecache.getline(' ??filename??   ',     # ??
                sys.stderr.write('az', 'el', 'AREA' )           # ??
有帮助吗?

解决方案

使用 shell=True 是错误的,因为那不必要的刺激了壳。

相反,这样做:

for el in ('90.','52.62263.','26.5651.','10.8123.'):
    if el == '90.':
        z = ('0.')
    elif el == '52.62263.':
        z = ('0.', '72.', '144.', '216.', '288.')
    elif el == '26.5651':
        z = ('324.', '36.', '108.', '180.', '252.')
    else el == '10.8123':
        z = ('288.', '0.', '72.', '144.', '216.')

    for az in z:

        exepath = os.path.join('Path where .exe file is')
        exepath = os.path.normpath(comstring) 
        cmd = [exepath, '-el', str(el), '-n', str(z)]

        print 'The python program is running this command:'
        print cmd

        process = Popen(cmd, stderr=STDOUT, stdout=PIPE)
        outputstring = process.communicate()[0]

        print 'The command returned the following back to python:'
        print outputstring
        outputlist = outputstring.splitlines()
        AspecificLine = outputlist[22]   # get some specific line. 23?
        print AspecificLine
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top