Got a problem using subprocess.Popen(..)
This command:
HG_REV = subprocess.Popen(["hg", "log", "-l", "1", "../"], stdout=subprocess.PIPE).communicate()[0]
gives me the following Error:
File "/usr/lib/python3.4/site.py", line 182
file=sys.stderr)
^
SyntaxError: invalid syntax
But this one works fine:
HG_REV = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE).communicate()[0]
Could anyone explain, why this error occurs and how to solve it?
Refered to this post: Mercurial scripting with python
================== UPDATE 1 ============================================== I figured out it has something to do with pydev and anything in my eclipse is probably changing the environment variables. I am pretty sure because running the above commands in a file (python3.4 test.py) on linux shell worked!!
Here are more information:
- Ubuntu 14.04.3 on virtual machine
- Eclipse Mars
- pydev
- python3.4 is the current configuration (when I switch to python2.7 it worked)
(I also tried hglib and the exact "same Error" occurs, when running
client = hglib.open(my_mercurial_repo)
because open is also using subprocess.Popen(..)
)
================== UPDATE 2 ==============================================
When setting PYTHONPATH
to /usr/bin/python3.4
the code works!! But the behavior seems weird to me. What is the common way for using python3.4 on virtual machine? The question is still not solved.