简体   繁体   中英

Running command on Windows fails with unknown flag due to single quote

I am trying to run the IBM Rational AppScan command line tool in python to iterate through .scan files in Windows and create xml reports. I am using python3.7.4 to do this and I am using the subprocess module. What I am trying continuously fails because of an unknown flag due to a single quote.

I am trying to run this python code on a Windows Server 2012. I have tried using os.system and subprocess.run with no luck.

Here is my code. It is looking for .scan files in the specified directory and when found attempts to run the command:

appscancmd r /b $scanfile /rtm Guidefault /rf $scanfile.xml /rt xml_report

Reference here for syntax:

https://www.ibm.com/support/knowledgecenter/en/SSPH29_9.0.3/com.ibm.help.common.infocenter.aps/r_ReportCommand004.html


import sys
import os
import subprocess

directory='C:\Scans'

for filename in os.listdir(directory):
    if filename.endswith(".scan"):
        scanfile=str(os.path.join(directory, filename))
        command=['appscancmd', 'r /b "'+scanfile+ '" /rtm GuiDefault /rf "'+scanfile+'.xml" /rt xml_report']
        subprocess.run(command)
        continue
    else:
        continue 

I keep receiving the error message:

Unknown flag entered: 'r /b "c:\\scans\\app.scan" /rtm guidefault /rf "c:\\scans\\app.scan.xml" /rt xml_report'

and I believe this is due to the single quote inserted. When I manually run:

appscancmd r /b "c:\scans\app.scan" /rtm guidefault /rf "c:\scans\app.scan.xml" /rt xml_report

it works fine. Not sure how to resolve this, so figured I would ask for help

Jason, i figured out how to break each in the command list and was able to execute successfully. Thanks! command=['appscancmd', 'r', '/b', scanfile, '/rtm', 'GuiDefault', '/rf', scanfile+'.xml', '/rt', 'xml_report'] did the trick for those wondering

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM