Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-28-2010, 08:05 AM   #1
LQ Newbie
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
Embedding Linux command in Jython script

Please can someone help me. I am trying to embed a command in a Jython script. The version of jython does not support popen so I am using os.system("pmap -x %s | tail -n1 |cut -f2 -dB" % (pid)) to get the memory consumption of a pid and pass same into my Jython script. The problem is that my code which looks like this:

cmd = "pmap -x %s | tail -n1 |cut -f2 -dB" % (pid)
memusage = os.system(cmd)

executes properly but does not assing the result into the variable "memusage". So when I used the variable elsewhere I get "0". How do I manage to get the variable to grab this value rather than it executing directly.

Last edited by sfaseyik; 01-28-2010 at 08:06 AM. Reason: i mistyped something
Old 01-28-2010, 08:38 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Hi, welcome to LQ!

That's because the os.system call just returns the processes status. If other
functions that support your intention aren't available you *could* pipe the
output to a file within the system call and then open the file for post-processing
if the command returned successfully.


P.S.: Moving this to programming.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
jython error kpachopoulos Programming 0 09-09-2007 04:11 AM
embedding a command for at? Xstack Linux - General 2 02-21-2005 03:42 PM
Embedding perl in bash script MikHud Programming 4 02-02-2005 06:26 AM
Python/jython games davholla Programming 1 01-07-2005 08:20 AM
Jython linuxRules Linux - Software 1 06-20-2002 11:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration