|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
passing file to program
Hi folks,
how are well all today... its bloody freezing here at the moment in Sydney ![]() if i have a file on the HD and want to pass it to a python script i use the sys.argv[x] which is fairly straight forward, however im trying to pass a file directly to my script after its been fetched via a pop email retrieve utility. i figured that sys.argv[x] still would of done that regardless if the file was on the HD or being piped from another program. im lost now so some help would be much appreciated. many thanks... |
|
#2
|
||||
|
||||
|
Again, I'd suggest you post your script. What are having problems with, exactly ? Is it with Python file I/O ?
__________________
Time is the greatest of teachers ; sadly, it kills all of its students. - Hector Berlioz |
|
#3
|
|||
|
|||
|
My apoligies solarbear...
Code:
#!/usr/bin/env python
import email, os, sys, smtplib, string
if len(sys.argv) == 1:
print "Usage: %s filename" % os.path.basename(sys.argv[0])
sys.exit(1)
file = open(sys.argv[1], 'r')
msg = email.message_from_file(file)
file.close()
fromaddr = 'MAILER-DAEMON'
toaddrs = msg['from']
subject = 'ERROR'
msgg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddrs, subject))
msgg = msgg + 'testing for now'
server = smtplib.SMTP('localhost')
#server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msgg)
server.quit()
As it standards the code works fine if the email is allready on the HD but like i said if the email is piped directly to the script it fails. I have tried many senarios with no success ![]() thanks |
|
#4
|
||||
|
||||
|
pipeing stdin
Hey sissy,
When working with pipes you can read them in though stdin (sys.stdin). Take a look at this article for more info. http://www.linuxjournal.com/article.php?sid=3946 Did you get my reply to your email? Have fun, Mark. |
|
#5
|
||||
|
||||
|
It has nothing to do with your question, but for how long do you live in Australia? Stupid question I know ... but a friend is in Sydney at moment ... perhaps you no him (improbably I know...)
|
|
#6
|
|||
|
|||
|
thanks Mark, i got ya email and have replied twice doesnt seem like your getting them?
Wizard, i have lived in Sydney for all my life 32years in fact ![]() |
|
#7
|
||||
|
||||
|
Hi sissy, i got one of your replies yesterday, have just replied. You mentioned error trapping, this is really easy with python. if you put out code in one or more try-except blocks you can provide alternatives actions if spacific errors occure.
Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > passing file to program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|