Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Sep 27th, 2005, 12:58 PM   #1
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Question Getting Python to talk to a program

Yo all!

I'm trying to get my cgi script to talk to a java program. Basiclly the java program can be run on the command line by typing:

Quote:
/the/location/of/the/program/foo -arg1 -arg2
then when the program is run with those arguments, it will ask for a password:

Quote:
/the/location/of/the/program/foo -arg1 -arg2
password:
After I put in the password, I want to withdraw all the lines of output that is created so I can work with them. I orgionally thought I could use popen, but that only seems good for a "one shot" type of deal, because it will return what the command that you gave sent off and give you back a popen object. I want this process to say open so I can write arguments to it and get the input.

Any thoughts? Thanks!
MegaArcon is offline   Reply With Quote
Old Sep 28th, 2005, 12:53 PM   #2
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Warg....O.K...I'm getting closer...

so, popen2 actually seems to work "somewhat" but not in the manner i need it to. popen2 returns a "sub shell" type of deal. It returns 2 fdopen objects, one for the output and one for inputting like the shell stdin. for instance:

from popen2 import popen2

r, w = popen2('wc -w')
w.write('foo foo foo')
w.flush()
w.close()

print r.read()
3

However, the java program I'm using prints "password: " to the screen and waits for a password. w.write dosen't seem to give it the password, and then even after I've closed the pipe ( w.close() ) it STILL keeps spitting the "password:" string at me. So, I figure that either the java program is doing some sort of fork, or using threads, or not taking it's input from stdin or something funkey like that.

Guess my next step is to write my own java program to emulate the program I'm working with and try to see what type of code adjustments I'll need to make in order to get this thing working....blech....editing and code-crawling other people's java code...ah well, such is the way of the programming world.
MegaArcon is offline   Reply With Quote
Old Sep 28th, 2005, 2:27 PM   #3
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Ahhhhhhhhhhh...O.K. The java program talks to div-tty, and dosen't actually touch the stdin. That makes sence now why the program kept spitting the password prompt at me. CGI dosen't actually have a tty and thus the program was stuck waiting for input from a source that cannot be written to.

lol...guess I really didn't have to post all this...but hey...might be useful to some other fokes round' er'. :p
MegaArcon is offline   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 6:14 PM.

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