473,287 Members | 3,181 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,287 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 1061
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: **************...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

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.