Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 13th, 2006, 1:00 AM   #1
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
Question: Calling other progs

I have a question about how to have a script call other progs (ie Word, Excel) and executing them. Can anyone point me in the general direction?
__________________
~ Silicon Enhanced Pudding
"It's magically delicious"
Silicon_Pudding is offline   Reply With Quote
Old Jun 13th, 2006, 1:05 AM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
I think that in Perl you use the ` ` and it executes the statement in the console. I am not sure but it might be similar in Phyton.
Wizard1988 is offline   Reply With Quote
Old Jun 13th, 2006, 1:07 AM   #3
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
import os
os.startfile("c:/windows/notepad.exe")
Sane is offline   Reply With Quote
Old Jun 13th, 2006, 1:23 AM   #4
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
Thanks
__________________
~ Silicon Enhanced Pudding
"It's magically delicious"
Silicon_Pudding is offline   Reply With Quote
Old Jun 13th, 2006, 5:40 AM   #5
demon101
Hobbyist Programmer
 
demon101's Avatar
 
Join Date: Mar 2006
Location: westboro, ohio
Posts: 160
Rep Power: 0 demon101 is an unknown quantity at this point
Send a message via Yahoo to demon101
Quote:
Originally Posted by Sane
import os
os.startfile("c:/windows/notepad.exe")

now sane with that code. could i configure it a little to open like a webpage or a picture on a web page?
__________________
Demon101 Production's

Code Forums
demon101 is offline   Reply With Quote
Old Jun 13th, 2006, 7:28 AM   #6
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Of course not. Those are two separate things. Unless you have a shortcut file to a webpage or a picture, then change the link in my code to that shortcut.

Otherwise you'll have to use urllib2 and save, then open, the output.

import urllib2
import os

# load this image:
image_in = "http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif"

# save it as:
image_out = "my_image.gif"

# prepare the opener for opening web pages
opener = urllib2.build_opener()

# load the image in to a string
page = opener.open(image_in) 
image = page.read()

# open the stream with binary mode enabled
stream = open(image_out, "wb") 
stream.write(image)
stream.close()

# open the image
os.startfile(image_out)
Sane is offline   Reply With Quote
Old Jun 13th, 2006, 1:52 PM   #7
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Firstly, bear in mind os.startfile is Windows specific (it won't work on Mac or Linux if you try to run your script there).

Sane: may be better if you mentioned it's win-only before you advocated its adoption.

Quote:
now sane with that code. could i configure it a little to open like a webpage or a picture on a web page?
No, if you want to open a webpage in a web browser in a cross-platform manner you use the webbrowser module:
import webbrowser
# open the webpage
webbrowser.open("http://google.com")
# open an image in the browser
webbrowser.open("http://www.google.com/intl/en/images/logo.gif")
as you can see, you use the same function for both - webbrowser.open.
Cerulean is offline   Reply With Quote
Old Jun 13th, 2006, 1:54 PM   #8
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
Quote:
Originally Posted by Cerulean
Firstly, bear in mind os.startfile is Windows specific (it won't work on Mac or Linux if you try to run your script there).
How would you perform this in Linux?
__________________
~ Silicon Enhanced Pudding
"It's magically delicious"
Silicon_Pudding is offline   Reply With Quote
Old Jun 13th, 2006, 4:38 PM   #9
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Use os.environ['OS'] or os.name to determine if it's linux. Then os.system("command") with the appropriate command that would be used to execute the program via linux command line.
Sane is offline   Reply With Quote
Old Jun 13th, 2006, 5:49 PM   #10
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
FYI, os.environ['OS'] doesn't work on my mac, while os.name does.
titaniumdecoy is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:40 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC