473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

popen2 issue

12
Hi All,
I am trying to do something new in python but at this moment i really don't know if it is possible.

I have a very simple python script that will simply prompt for any text and when the text it entered by a user the script will display it on a screen.

Expand|Select|Wrap|Line Numbers
  1. myInput = raw_input("Write something:")
  2. print myInput
  3.  
What i am trying to do is to start this simple script from another python script, read the prompt and write something to the first script. Let's say that the answer will be hardcoded to simple "Hello". In that case if the other script that starts the simple one and prints the result would print

Expand|Select|Wrap|Line Numbers
  1. Write something:
  2. Hello
  3.  
I will keep looking for a solution for this problem. I will really appreciate any hints from you, especially if it is actually possible to do :-)

Thanks in advance for any help.

Best regards,
Oct 25 '07 #1
3 1065
rhitam30111985
112 100+
i cant think how u can start another script from a scrip but this is all i can think of :

script1.py:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. string=raw_input()
  3.  
script2.py

Expand|Select|Wrap|Line Numbers
  1.  
  2. from script1 import *
  3. print string
  4.  
  5.  
Oct 25 '07 #2
elcron
43
As far as I'm aware there is no such way but object oriented languages like python have functions and classes for code reuse. I would use the import statement.

Expand|Select|Wrap|Line Numbers
  1. # script1.py
  2.     from script2 import formatText # import the function
  3.  
  4.     # execute the first logic
  5.     myInput = raw_input("Write something: ")
  6.     print myInput
  7.  
  8.     # call upon function
  9.     print formatText(myInput)
  10.     print myInput
  11.  
  12. # script2.py
  13.     def formatText(texts):
  14.         text = texts[:] # copies the variable so you can avoid side effects
  15.         ## format the text ##
  16.         text += '\n'
  17.         text *= 5
  18.         return text
  19.  
Oct 25 '07 #3
Bierny
12
Hmm...
What in case when the first script (the one that uses raw_input) is not a python script, but simply some other script that i can only execute?

I am still trying :-)

Thanks for your comments and i am waiting for new ones :-)

Best regards,
Oct 26 '07 #4

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

Similar topics

1
by: Guy | last post by:
Hi I was given an exstremly useful answer to a problem that I had in windows. I'm relativly new with python, but find it exstremly useful. I'm creating a script to run test files and record...
1
by: A. Lloyd Flanagan | last post by:
OK, I've got a weird one I haven't been able to figure out yet. Admittedly I haven't had time to dig into the library source, but this behavior certainly doesn't seem right. Here's a test case: ...
1
by: | last post by:
This could possibly be a bug, but I don't understand it fully so I'm posting here first. Searching the list told me other people are having this problem too. I have created a class which...
4
by: P | last post by:
I've written a couple of apps that required running a command and grabbing the output, and I've found the existing interfaces problematic for this. I think the proliferation of functions and...
1
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): ---------------------...
1
by: Magnus Lycka | last post by:
I'm trying to read standard out in a process started with popen2 in a non-blocking way. (Other good ways of doing this than the one I tried are appreciated.) I've tried to dumb down my code to...
9
by: Martin P. Hellwig | last post by:
Hi all, I was doing some popen2 tests so that I'm more comfortable using it. I wrote a little python script to help me test that (testia.py): --------------------------------- someline =...
3
by: mikem76 | last post by:
How do I automatically redirect stdout and stderr when using os.popen2 to start a long running process. If the process prints a lot of stuff to stdout it will eventually stop because it runs out...
1
by: mikem76 | last post by:
Is there a way to get the process id when starting a process using os.popen2 or os.popen3 on linux? Mike
1
by: diego | last post by:
I'm trying to understand how popen2 works. Found in this group, that popen2.popen2 can cause trouble so i chose win32pipe.popen2. have a look a the listing of 2 files: ekmain.py: **************...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.