I’ve been trying to get a PHP script to execute a Python script today using PHP’s @exec@ call. This worked fine, until I entered a long amount of data on the command line (this is using Windows XP by the way)…
I need to pass the body of my blog entries to the Python script. As I can’t find a RSS parser I like written in Python, and am not skilful in Python, I wanted to do most of the work in PHP. I’m calling the python script from PHP like:
@exec(”c:/code/RSS_Manager/test.py ” . $item['description'], $output, $ret);@
This worked fine until I encounterd an entry *3560* characters in length. Then Windows threw the error:
bq. Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.
I know it’s not the script at fault, as I commented out the contents. Can anyone suggest a different way to pass this data to the python script? I’ve thought of using temp. files, but I’m hoping there’s another way to do it instead.
The command that caused Windows problems is in the extended entry. And I did try escaping quotes etc - made no difference
h3. Command Follows
@test.py Recently I’ve been looking at, and thinking about, email clients. I’ve been using Eudora now for nearly 2 years, and have been getting more and more dissatisfied with it. I have somewhere over 80000 emails in folders/mailboxes; currently I recieve over 2000 emails a month (mostly from mailing lists) but before I unsubscribed from many of them I was getting nearly 7000 messages a month. Email is data. And the problem with today’s email clients is that most weren’t designed to handle the volume of messages we receive today. Opera’s M2 has pointed the way. Access points, a central database of messages… all good. But I think it needs taking further. Many of us red high volume mailing lists. If you’re on too many (which is very easy, as so many have the occasional interesting/useful thread), it gets hard to keep up and pick out the messages of interest. I’d like to see some kind of in-built AI, along the lines of the Bayesian spam filters, that depending on your ranking of previous messages flags those it thinks you’d be most interested in. Access points, or views as some people call them, are extremely useful. Instead of having a rule to copy all messages containing a certain string to a folder, I set up a view. This prevents having duplicate messages with the consequental increase in disk space required. I believe that newsgroups should be closely integrated. It should be (practically) invisible to the user whether the message they’re reading/replying to is an email or a newsgropu posting - after all, why should it matter? Attachments should be able to be filtered into folders. One of my biggest complaints about Eudora is that I can’t do this - so photos from a couple of photo-only mailing lists end up mixed together, along with all the other crud attachments (Eudora’s attach folder currently has over 900 attachments in it). This makes management of the files much harder than it should be. I don’t want the mail client to come with an in-built spam filter. There’s plenty of stand-alone tools to do this instead, and they have the benefit that if you change email clients then you don’t have to start training all over again. I’m a great believer in each tool being specialised and only doing what it’s good at. An email client must easily support multiple email addresses or/and POP3 accounts. I have an infinite number of addresses (due to a catch-all) and over 10 domains I manage. I need an easy way to send a message from any of them - ideally by typing the address I want into the “From” field of the message. Some email clients ‘bung’ all messages from multiple POP3 accounts into the same folder tree; others (like The Bat!) give them separate trees. I’m not sure which is best - I always use only 1 POP3 account and redirect email from all my addresses to it. An unusual approach? Maybe, but it means I only have to enter 1 password to check my email (Eudora won’t store the password for me). In the end it comes back to the fact that as yet we don’t have very good information/knowledge management tools. This is the case in all areas - look at the struggles charted in this weblog as I try to find a tool suitable for posting links I find, source code, and articles like this. What’s currently available? Short answer loads and loads of similar email clients. Long Answer Plenty to keep you occupied if you want to test them. I haven’t tested many - usually because they are 30 day trials, and ’sometime in the future’ I may want to test them more seriously than I do now. Below are a few with innovative features…@
3 comments ↓
Take a look at the PHP popen() function, or maybe even proc_open() if you are running PHP 4.3. These functions allow you to start up a sub-process and then write data to it as if it were a file. The data written to the process is available to it on its standard input, which in Python’s case means using sys.stdin.read(). I don’t know how reliable those functions are on Windows though.
If you can’t get those working, there’s nothing inherently wrong with using a temp file to pass data from one process to another.
Cheers,
Simon
Thanks (yet again) Simon! I’m not sure why using @popen()@ would make such a difference to using @exec()@ - possibly I was exceeding the memory limit of PHP before? - but it’s working now
Time to buy a Python book I think - I want to learn more, and the online docs don’t seem to be good enough for em (they’re not as good as the PHP documentation IMO).
Oh no, got to use @proc_open@ as I need 2-way communication (I think anyhow - as I send + receive data). Damn - I was looking forward to something simple!
Leave a Comment