سؤال

هذا هو البرنامج النصي الذي أعمل عليه. من المفترض تشغيل ملف .EXE للحلقة أدناه. (بالمناسبة لست متأكدا مما إذا كان مرئيا ولكن بالنسبة إلى EL IN ('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