0

I have a bash script, which is running perfectly:

gvim --servername "servername" 1ドル
if [ -f ${1%.tex}.pdf ];
then
 evince ${1%.tex}.pdf &
fi
evince_vim_dbus.py GVIM servername ${1%.tex}.pdf 1ドル &

I am trying to convert it to python as:

#!/usr/bin/env python3
from subprocess import call
import sys, os
inp_tex = sys.argv[1]
oup_pdf = os.path.splitext(sys.argv[1])[0]+".pdf"
print(oup_pdf)
call(["gvim", "--servername", "servername", sys.argv[1]])
if os.path.exists(oup_pdf):
 call(["evince", oup_pdf])
call(["evince_vim_dbus.py", "GVIM", "servername", oup_pdf, inp_tex])

in the python, both gvim and evince window is open, but evince_vim_dbus.py line is not working. Not that it is giving any error, but it is not showing intended result, as it should, and is doing with the bash script.

trying with check_call (I have to kill it after a while, here's the traceback):

Traceback (most recent call last):

 File "/home/rudra/vims.py", line 28, in <module>
 check_call(["python","/home/rudra/bin/evince_vim_dbus.py", "GVIM", "servername", oup_pdf, inp_tex])
 File "/usr/lib64/python3.5/subprocess.py", line 576, in check_call
 retcode = call(*popenargs, **kwargs)
 File "/usr/lib64/python3.5/subprocess.py", line 559, in call
 return p.wait(timeout=timeout)
 File "/usr/lib64/python3.5/subprocess.py", line 1658, in wait
 (pid, sts) = self._try_wait(0)
 File "/usr/lib64/python3.5/subprocess.py", line 1608, in _try_wait
 (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt
Jean-François Fabre
141k24 gold badges179 silver badges246 bronze badges
asked Dec 30, 2016 at 22:14
18
  • call(["gvim", "--servername", "'servername'", sys.argv[1]]): there are single quotes within double quotes, is that a typo? Commented Dec 30, 2016 at 22:25
  • can you check return code of the commands? and why calling a python script inside another when importing is so easy? Commented Dec 30, 2016 at 22:30
  • I am running Linux Commented Dec 30, 2016 at 22:30
  • done! single quotes are removed. Commented Dec 30, 2016 at 22:32
  • BTW, your original bash actually has a bunch of bugs -- try using it to process a file with spaces in its name to see. Consider running it through shellcheck.net and fixing the problems identified. Commented Dec 30, 2016 at 22:33

1 Answer 1

1

I'm going to have a guess that your real problem isn't the evince_vim_dbus.py line itself, but rather the gvim line, because you pass it the server name 'servername' instead of simply servername, and so doesn't match the name on the line that runs evince_vim_dbus.py.

I'm not familiar with gvim or its server functionality, but I'm guessing the evince_vim_dbus.py program connects to gvim using the given name, in which case it's going to fail since the server of the right name isn't running.

If that's not it, then maybe the problem is that subprocess.call() runs the given program and waits for it to exit, whereas in your original bash script, you run evince with an ampersand, causing bash not to wait for it, so maybe the problem is that evince_vim_dbus.py never runs at all until you exit Evince.

answered Dec 30, 2016 at 22:24
Sign up to request clarification or add additional context in comments.

4 Comments

I have gvim --servername "servername" 1ドル in bash, with "severname" under quote.
@BaRud, sure but those quotes are consumed by bash and aren't passed into gvim. In fact, those quotes were no-ops and completely extraneous.
Tried this: call(["gvim", "--servername", "servername", sys.argv[1]]), with no result.
@BaRud, ...to be clear, those quotes are syntactic in bash -- they're instructions to the shell, not passed to gvim in the argv array used in the execv-family syscall that does the actual heavy lifting of starting an external command. Because you don't have any shell when using subprocess.call() in this manner (and don't add shell=True, that's creating more problems!), there's nothing for those quotes to be parsed/consumed by.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.