473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to control an application using python script

14 New Member
I have a cygwin application which i have invoked using python script like:
os.system("path of the exe file")
How can i enter text in the cygwin( which has appeared )using the python script itself???
Nov 7 '06 #1
10 14269
fuffens
38 New Member
Are you running Python directly from Windows or from CygWin? In case you run Python from Windows you probably need to use COM to send text to the CygWin window. The win32com module can be used (included in the PythonWin distribution). Look at other posts here for more information.

I would suggest that you build Python on CygWin instead (or download Python built for CygWin) and then you can make any os.system call you want to instead of sending text to the CygWin window.

Best regards
/Fredrik
Nov 7 '06 #2
kudos
127 Recognized Expert New Member
Can you do something like this?
Expand|Select|Wrap|Line Numbers
  1.  
  2. import os
  3.  
  4. fd = os.popen("your program that requires user input","w")
  5. fd.write("some input\n")
  6. fd.close()
  7.  
  8.  
(or have I completely misunderstood the question?)

-kudos

I have a cygwin application which i have invoked using python script like:
os.system("path of the exe file")
How can i enter text in the cygwin( which has appeared )using the python script itself???
Nov 7 '06 #3
learnerofpython
14 New Member
thanks for all ur valuable suggestions.
Whenever i use popen to invoke cygwin application or any other application(e.g a simple notepad) the application is not appearing on the screen


eg.
import os

fd = os.popen("C:\cy gwin\cygwin.bat ","w")
fd.write("telne t 101.29.34.132")
fd.close()

i am unable to view any changes this program makes
Nov 8 '06 #4
bartonc
6,596 Recognized Expert Expert
thanks for all ur valuable suggestions.
Whenever i use popen to invoke cygwin application or any other application(e.g a simple notepad) the application is not appearing on the screen


eg.
import os

fd = os.popen("C:\cy gwin\cygwin.bat ","w")
fd.write("telne t 101.29.34.132")
fd.close()

i am unable to view any changes this program makes
Nope, that won't work. The object of popen() must have an input (like sys.stdin) and an output (like sys.stdout), so using a batch file to invoke the process won't work. Check out 2.4 docs section 6.9 for examples.
Nov 8 '06 #5
kudos
127 Recognized Expert New Member
try this...

Expand|Select|Wrap|Line Numbers
  1. import os
  2. input,output= os.popen2("some command","t")
  3. input.write("some input")
  4. print output.readline()
  5.  
  6.  
input is like file write(w) part, while output is the file read part(r)

-kudos
Nov 8 '06 #6
learnerofpython
14 New Member
no kudos, it didnt work.
barton i cudnt find section 6.9 in doc 2.4
please any1 help me out
Nov 8 '06 #7
fuffens
38 New Member
Here is a really lame solution to your problem. I do not have CygWin installed on my computer so I open notepad and send text to it instead. I think you can make it work for CygWin.

Expand|Select|Wrap|Line Numbers
  1. from win32com.client import *
  2. sh = Dispatch("Wscript.Shell")
  3. sh.Run("notepad")
  4. sh.AppActivate("Untitled");sh.Sendkeys("Hello!");sh.SendKeys("{Enter}")
Kodus, thank you for pointing to the popen function in the os module. I think that is the correct way to go for a stable, general solution. I could not however get it to work. I will do some reading on popen later.

BR
/Fredrik
Nov 8 '06 #8
fuffens
38 New Member
...and here is one for the command window also...

Expand|Select|Wrap|Line Numbers
  1. from win32com.client import *
  2. import time
  3. sh = Dispatch("Wscript.Shell")
  4. sh.Run("cmd"); time.sleep(1);sh.Sendkeys("dir");sh.SendKeys("{Enter}")
Nov 8 '06 #9
kudos
127 Recognized Expert New Member
hmmm...It might be true that telnet won't work with popen. When I think about it, I vaugly remember trying log into telnet via popen (in C, but I guess that is basically the same function/method). It think it had something to do with security (i.e. not allowing people to make scripts with password databases). Anyway, im sitting on a windows machine, and I have no longer an account where I can login from telnet, so I won't be able to test it...

-kudos
Nov 8 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2463
by: Susanne | last post by:
Hello! In have embedded python into my MFC application. It works fine using the PyRun_SimpleString method, giving it a string with some simple commands. When i am using PyRun_SimpleFile instead, my application crashes. I have also created a console application. There i also call PyRun_SimpleFile. The console application executes the given script.
7
2402
by: Bo Peng | last post by:
Dear Python group: I am planning on an application that involves several complicated C++ classes. Basically, there will be one or two big data objects and some "action" objects that can act on the data. I would like to use a script language to control the interaction between these c++ objects. I become interested in Python since it can load C++ objects and can even extend C++ classes. However, I am not quite sure to what extent can...
8
2052
by: Jarek Zgoda | last post by:
What you consider a "best way to deploy linux python app"? I don't want to install library modules into user's site-packages, so distutils is no help. Currently, I change sys.path (adding directory where library modules are stored) and I ask users to install application into /opt hierarchy, but I don't think it's optimal. -- Jarek Zgoda http://jpa.berlios.de/
26
7730
by: Wolfgang Keller | last post by:
Hello, is it that my know-how to use Google is insufficient or... ....does really noone use Python for industrial control applications? At least I didn't manage to find any publicly available modules for such things as OPC/fieldbus communication etc... TIA,
7
4776
by: tlviewer | last post by:
hello, If you run the Mainboard monitor, speedfan, here is an ActivePython script to force automatic fan control.         http://www.almico.com/speedfan.php It's a great example of how clean the WinApi interface is in ActivePython. The script sets focus to the checkbox of interest and toggles the checkbox. AFAIK, speedfan will only start without fan control, requiring the user to manually
15
4782
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
5
7543
by: Chandra | last post by:
Hi, Is there a way to execute a python script(file) in ASP.NET application (programmatically)?? Regards, Chandra
0
999
by: fabien.lyon | last post by:
hello, The C++ application uses a python module which wraps commands set for CVS management: checkout, checkin and tag. We used python2.5.1 and Visual C++ 6.0 The problem we get is: After a good import and definition of python functions we have a random unhandled exception (from python25.dll) when calling python interface function several times.
0
1367
by: fabien.lyon | last post by:
-----Message d'origine----- De : fabien.lyon Envoyé : mercredi 30 mai 2007 20:16 À : 'python-list@python.org' Objet : RE: embeded python progam into visual C++ application crash 2.5.1 is compiled with Visual Studio 2005 - I hope you had no problems with VC++ 6.0?
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.