Q: Python cannot find my file when executing, calling, etc.

21 views
Skip to first unread message

John Sintal

unread,
Nov 8, 2012, 11:17:48 PM11/8/12
to reviewbo...@googlegroups.com
Hi,

I hope it is okay for me to post a programming related question here. I hope it doesn't spam the entire group w/ this question. Let me know! I tried IRC, been it seems ppl are away from keyboard (AFK).

I am trying to run patch and/or git apply for my rb patch command (WIP here http://reviews.reviewboard.org/r/3440/). I think I get the string command correct. For example, my rb patch would generate a string like "git apply /tmp/tmpX/' or 'patch -pX < /tmp/tmpx'.

If I run that string in my terminal, the patch would work fine. However, every time I run it through execute(), call(), I get OSError: [Errno 2] No such file or directory.  I've also tried this on trivial files, such as the ones in the current directory, and I still get the same error. Clearly, python is not happy when it tries to find a file listed as an argument to a command. I've also tried \\ (double backslashes) and still no luck.

Any one got any hints to solve this issue? I've been stuck on this for quite some time.

David Trowbridge

unread,
Nov 9, 2012, 3:48:21 AM11/9/12
to reviewbo...@googlegroups.com
John,

My guess is that you're passing in one big string where what is really expected is a list of arguments.

When you execute something from the shell, such as "git apply file.patch", your shell parses that up into three things: "git", "apply", "file.patch" and constructs an argv vector to invoke the process with. From your patch, I see you creating strings with the command as you might type it into your terminal, which you then (supposedly) pass into execute(...). I think it'll work better if you create a list of arguments like ['git', 'apply', '-p', p_num, patch_file] and then give that to execute().

-David


-David
Reply all
Reply to author
Forward
0 new messages