1

I'm trying to, from a command line, open an instance of konsole and run a python script. I'm trying:

konsole -hold -e  'python -i hello.py'

The behaviour I'm getting is that a persistent konsole opens, and I am dropped into python, but the script does not run.

Python 2.7.2+ (default, Oct  4 2011, 20:03:08) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

What do I need to do to get the python script to run in the konsole window?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
abalter
  • 9,663
  • 17
  • 90
  • 145
  • By the way: (1) the file "hello.py" has the line print("hello from python") (2) My ultimate goal is to have an "external tool" in Kate that runs the current script. I'm trying: cd "%directory" && konsole -e 'python -i "%filename"' and I get the same behaviour I described above using the command from a command line. – abalter Apr 12 '12 at 18:43
  • I don't use `konsole`, but the `-e` parameter is familiar from `xterm`. You seem to be using it properly; that works fine with `xterm`. – Mattie Apr 12 '12 at 18:48

2 Answers2

2

The problem is the way "konsole" uses the parameters after the -e switch - it seems like it simply pass them in a call that does not interpret the space separators as parameter separators.

However, if you don't put your call parameters inside quotes it will work - that is, simply:

konsole --hold -e  python -i hello.py

(I just tested it here)

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • I just tested it from a gnome terminal and it failed. ariel.balter@galactus:/nfs/concen/usr2/cslab/home/ariel.balter /Documents$ ls *.py hello.py I get the following error in the konsole window that opens: /usr/bin/python: can't open file 'hello.py': [Errno 2] No such file or directory – abalter Apr 13 '12 at 18:29
2

jsbueno's solution is the correct one. However, as described here, you can also do something like this ...

konsole --hold -e /bin/sh -c "python -i hello.py"

P.S. you'll need to specify --workdir (before the -e arg), or provide the full path to the python script, if it's not always in the initial working dir of konsole. But, you probably already knew that.

Marty
  • 7,920
  • 1
  • 20
  • 10
  • You might want to look more closely at the P.S. in my answer. If you're getting `[Errno 2] No such file or directory` for `hello.py`, it seems likely that konsole has a different initial current working directory than you expect. – Marty Apr 13 '12 at 19:02
  • By golly, that did it! Sorry for not paying attention to the P.S. – abalter Apr 13 '12 at 20:05
  • And it worked as an external tool in Kate, which was what I really wanted to accomplish. – abalter Apr 13 '12 at 20:08