简体   繁体   中英

Running command with python subprocess.call fails but works correctly when typed into cmd.exe

So the background on this is that I'm trying to setup a Cocos-2dx v3.0 project. I've gotten the python script that creates the project to run and now I'm trying to build and run the project so I can start development on a game. The issue I'm running into, as per the question, is that one of the commands issued by subprocess.call fails every time the build and run python script is run. When I run the exact command being passed to it in the shell myself however, it runs perfectly.

The method in python calling subprocess.call:

@staticmethod
def run_cmd(command, verbose):
    if verbose:
        Logging.debug("running: '%s'\n" % ''.join(command))
    else:
        log_path = CCPlugin._log_path()
        command += ' >"%s" 2>&1' % log_path    
    print "CALLING run_cmd"
    ret = subprocess.call(command, shell=True)
    if ret != 0:
        message = "Error running command, return code: %s" % str(ret)
        if not verbose:
            message += ". Check the log file at %s" % log_path
        raise CCPluginError(message)

This is used multiple times in the script and succeeds every other time.

The command that is failing when called from python but which runs fine when directly input to cmd:

"C:\Users\Patrick\Downloads\apache-ant-1.9.4-bin\apache-ant-1.9.4\bin\ant" clean debug -f C:\HyperFusion\RuneWars\RuneWars\proj.android\build.xml -Dsdk.dir="C:\Users\Patrick\COPAP\Software\adt-bundle-windows-x86-20130522\sdk"

Any and all help would be appreciated. I've done a bunch of googling but haven't come across anything that would seem to help. I'm new to python (and really didn't expect to have to debug it since these are only setup scripts provided by Cocos) so my apologies if I'm missing something simple here.

OS is Windows 7 if that has any bearing on the issue.

Thanks!

There was a reason why I've asked about 'verbose' flag. If it's set to 'False', try to comment out one line as shown below:

 else:
    log_path = CCPlugin._log_path()
    # command += ' >"%s" 2>&1' % log_path    

What could happen there was that the next command won't be able to open the log file for writing because it has been already opened by the previous command.It could be a good explanation why every other command succeeds as you wrote.

Just a hypothesis that should be easy to check. Good luck!

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