LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-17-2010, 04:23 PM   #1
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Rep: Reputation: 21
simple to some 3 hours wasted for me question


Code:
bba = (os.system("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\s.*//' "))
	bbb = (os.system("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\S*\s*//' "))
	
	print bbb
568
398
0

I can't figure why this prints the returned correct bba and bbb values even when I don't ask it to and when I issue the print bbb it gives a zero. I'm trying to plug in these values into Qcanvas resize command and it's taking the 0, 0 instead of the correct returned values.

c.resize(bba, bbb)
 
Old 03-17-2010, 04:26 PM   #2
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
forgot

running pyqt3
 
Old 03-17-2010, 04:29 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by gary_in_springhill View Post
Code:
bba = (os.system("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\s.*//' "))
	bbb = (os.system("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\S*\s*//' "))
	
	print bbb
568
398
0

I can't figure why this prints the returned correct bba and bbb values even when I don't ask it to and when I issue the print bbb it gives a zero. I'm trying to plug in these values into Qcanvas resize command and it's taking the 0, 0 instead of the correct returned values.

c.resize(bba, bbb)
If you run the command lines outside the Python script, do they print the lines ?

If they do, why do you think the lines shouldn't be printed from your Python script ?
 
Old 03-17-2010, 04:35 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Because the return value isn't what they're outputting to the screen, it's the return value from the execution of the commands in the shell (eg: 0 is normal termination). If you want to actually grab stdout I think you need to do something more like this:

Code:
bba = Popen("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\s.*//' ", stdout=PIPE, shell=True).stdout.read()
bba = Popen("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\S*\s*//' ", stdout=PIPE, shell=True).stdout.read()
You might have to do some escaping to get this to work and I think popen is part of subprocess. YMMV... Python isn't my language of choice

Edit: What's currently happening is this
system call -> grep %%BoundingBox: ~/hpgl-hot-folder/*.job | sed 's/%%BoundingBox: 0 0 //' | sed 's/\s.*//'
Output to STDOUT: 568
Return: 0
Set bba = Return Value

system call -> grep %%BoundingBox: ~/hpgl-hot-folder/*.job | sed 's/%%BoundingBox: 0 0 //' | sed 's/\S*\s*//'
Output to STDOUT: 398
Return: 0
Set bbb = Return Value

print bbb -> outputs 0 (because that is what bbb got set to)

Basically you need to set your variable to the stdout and not the return value.

Here, check this out: http://docs.python.org/library/subpr...ule-subprocess

Last edited by rweaver; 03-17-2010 at 04:48 PM.
 
Old 03-17-2010, 04:41 PM   #5
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
thanks

Thanks so much it made other errors make sense now also.

Again thanks so much
 
Old 03-17-2010, 05:42 PM   #6
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
worked like a charm

Works great after conv. to int

Thanks so much
 
Old 03-18-2010, 10:22 AM   #7
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
So what was the final code you ended up using out of curiosity (it might help someone else with the same problem in the future)?
 
Old 03-19-2010, 01:35 PM   #8
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
sorry about that

I should have auto posted the solution:

Code:
bba = subprocess.Popen("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\s.*//' ", stdout=PIPE, shell=True).stdout.read()
	bbb = subprocess.Popen("grep %%BoundingBox:   ~/hpgl-hot-folder/*.job | sed  's/%%BoundingBox: 0 0 //' | sed 's/\S*\s*//' ", stdout=PIPE, shell=True).stdout.read()
	bba = int(bba)
	bbb = int(bbb)
	c = qtcanvas.QCanvas(self) # <- gives the canvas a parent QObject
	c.resize(bba, bbb)
 
1 members found this post helpful.
  


Reply



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
Cron Question - Delete files in a dir older than 48 hours? t3___ Linux - Newbie 5 10-11-2011 03:42 AM
open discussion: Countless human hours wasted configuring Linux displays balsam Linux - General 52 06-03-2010 01:08 PM
Linux machine gets stuck after 8 hours or 12 hours fahadaziz Linux - Newbie 4 03-28-2010 04:19 PM
Simple Linux installation followed by severe machine slowdown 4 hours later tanguero750 Linux - Newbie 10 10-04-2009 08:44 AM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:20 PM.

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