0

p4.exe is the perforce command line tool (git/cvs/svn like tool). I am trying to launch several ms-dos commands 'p4 resolve' in an python script. because I have a hundred files to resolve.

However I cannot launch 'p4 resolve -m' as I want (which automatically opens my 3-way merge tool on the conflicting files). p4 doesn't accept the m as an executable parameter.

Instead, manually, I must do 'p4 resolve', then wait for the prompt to ask me for an option, and then only type 'm' there.

Do you know in python how I could feed the input since I cannot pass the 'm' parameter to the command line tool p4.exe.

For the moment I use os.system(myDosCommand)

5 Answers 5

2

Use the shell option command with subprocess

import subprocess

retcode = subprocess.call(["p4", "resolve", "-m"], shell=True)
Sign up to request clarification or add additional context in comments.

Comments

2

If you simply want Perforce to auto-merge all pending integrations:

p4 resolve -am

Comments

1

Something like...

from subprocess import Popen

resolve = Popen(["p4", "resolve"])
stdout, stderr = resolve.communicate("m")

3 Comments

i've chosen yours as the good answer. However, I do have read that "from X import Y" is not the most pythonic way of importing ;-)
@StephaneRolland: where did you read that? PEP8 makes no problem of it. You must be thinking of from X import *, which I would never write.
oh, I have generalized too much ;-)
0

Have you tried merely piping the input to the command?

In cmd.exe:

C:\> echo m | p4 resolve

Comments

0

If you're using Cygwin you can try pexpect, a pure Python version of the TCL utility expect.

Adapted from the documentation:

child = pexpect.spawn('p4 resolve')
child.expect('Some string that p4 resolve presents')
child.sendline('m')

I don't know of any options not using Cygwin and I found a post about installing Cygwin just to get pexpect to work, so perhaps there isn't a better alternative.

1 Comment

It's not supposed to work on Windows. But it does work on Cygwin, I added a note about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.