Python Subprocess Behavior with Eclipse
Question: I am trying to run Eclipse from the command line to automate some project
importing and i am having an issue with pythons subprocess. Subprocess seems
to be ignoring my command arguments and just running eclipse straight up.

Here is what i am trying to do:

    
    
    subprocess.call(["C:/eclipse/eclipsec",
                     "-nosplash",
                     "--launcher.suppressErrors",
                     "-application org.eclipse.cdt.managedbuilder.core.headlessbuild",
                     "-data", workspace_dir,
                     "-import", project_dir])
    

But when i run this Eclipse just opens and doesn't perform the import. However
if i change the command to:

    
    
    subprocess.call(['eclipse_import.bat', workspace_dir, project_dir)])
    

Where `eclipse_import.bat` is:

    
    
    set workspace_dir=%1
    set project_dir=%2
    
    C:/eclipse/eclipsec -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data %workspace_dir% -import %project_dir%
    

Then everything behaves exactly as i expect it to.

Any ideas as to what would cause the differences?


Answer: They way you're calling it _should_ work properly, and I don't know why it
isn't. Perhaps Eclipse is trying to accept arguments in an odd way that your
batch script handles correctly but `subprocess.call()` doesn't, but that's
entirely conjecture on my part.

As a alternative, you can try calling it with the `shell=True` argument and
make your argument list a string instead:

    
    
    call_string = "C:/eclipse/eclipsec -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data {} -import {}".format(workspace_dir, project_dir))
    
    subprocess.call(call_string, shell=True)
    

This will cause your default shell to parse the arguments instead of doing it
natively in Python, which is very similar to your batch script workaround.

