0

I am writing a sublime plugin in Python. But I am still very new to Python language. I am using this line to call meld in Python:

if meld_cmd == None:
   meld_cmd = "C:\\Program Files (x86)\\Meld\\meld\\meld"
os.system('"%s" "%s" "%s" ' %(meld_cmd, source_name, dest_name))

It doesn't work well in Windows. The cmd window just flashes for a sec (seem to execute something) then disappears. I print the executed string out in sublime and copy the string into cmd window and execute. It executes well in both admin and non-admin mode. And I tried to add a pause before executing:

os.system('pause && "%s" "%s" "%s" ' %(meld_cmd, source_name, dest_name))

This works well too after clicking enter after the press any key to continue... line.

Not sure how to debug this and what is the reason why it is failing.

Lance Shi
  • 1,127
  • 3
  • 13
  • 28

2 Answers2

1

cmd.exe /c command has a parsing quirk when the command starts with a quote and has more than two quotes. The exact rules are explained in the online help text available via cmd /?:

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote characters
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

To get around this, just wrap the whole command in quotes, e.g. '""%s" "%s" "%s""' % (meld_cmd, source_name, dest_name).

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
0

Probably the problem is that you need to execute that script with Admin privileges.

Proceed to question How to run python script with elevated privilege on windows to get more information on that topic.

Community
  • 1
  • 1
Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82