[SOLVED] simple to some 3 hours wasted for me question
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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 ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.