Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 31st, 2004, 01:00 AM
shyam prasad cs shyam prasad cs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 shyam prasad cs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 21 sec
Reputation Power: 0
Intelligent python script

Hi All,
I want to know if it is possible to write an intelligent python script which accepts inputs from a text file (which was intended to be given through keyboard) and executes a program.
Eagerly waiting for reply,
Shyam

Reply With Quote
  #2  
Old May 31st, 2004, 03:00 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,203 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 17 h 2 m 54 sec
Reputation Power: 262
The answer is yes, but your question is so vague as to be meaningless. What sort of input? What sort of program?

here is a program that will fulfill your requirements:

Code:
import os
some_text = os.stdin.readline()   #read input from a file or the keyboard
os.system('aprogram.exe')  #execute a program


but it does not do anything useful.

What do you mean by intelligent? Do you mean read in english text and understand it? That will take a little more work.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old May 31st, 2004, 04:12 AM
shyam prasad cs shyam prasad cs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 shyam prasad cs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 21 sec
Reputation Power: 0
Intelligent python script

Thanks for the reply,
Sorry for the ambiguous question.
What I meant was-
Instead of giving input through keyboard(STDIN),I want to give inputs through a file.For example, consider a simple C program used as a calculator.Let it accept a keyboard input and based on that, it performs an operation(add,subtract,mul,div). What I want to do is, instead of giving keyboard input,I want to feed it through a file like "input.txt".The content of this file is:
Add
Sub
Mul
Div
Can my excutable (say "calc.exe",the C file being "calc.c" ) take inputs from "input.txt" one by one and perform all the 4 operations one after the other ?How can I do this using python (automating keyboard input) ?
My python script must be intelligent enough to feed these inputs(add,sub,mul,div)one by one to the executable calc.exe.
Regards,
Shyam

Reply With Quote
  #4  
Old May 31st, 2004, 04:41 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,203 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 17 h 2 m 54 sec
Reputation Power: 262
If the C program reads input from stdin, then you do not need Python to read the inputs from a file - you can do it on the command line by redirecting stdin using '<'.

e.g.

C:\> calc.exe < input.txt

This will execute calc.exe, reading the input from input.txt as if it came from the keyboard. (In the above example, "C:\> is the Windows DOS prompt, but this will work in both DOS and UNIX).


If you want more control then you can do it in Python using a pipe.
Code:
import os
f = open('input.txt')
pipe= os.popen('calc.exe', 'w')
for line in f:
   ...do stuff with line...
   pipe.write(line)


Dave - The Developers' Coach

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Intelligent python script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway