473,491 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

still trying to pass strings to the OS

I posted on this topic a few days ago, got a tip to use popen to
redirect stdin. Here's where I'm at now:

import popen2
r,w,e = popen2.popen3("/usr/bin/passwd")
print r.readline()
w.write("password")
w.flush()

When this is ran, the shell responds with "New password:" at the console
and then nothing happens. I can key in the password and then confirm it
manually after which "print r.readline()" does its thing by printing out
"Changing password for user." Note that when the command is ran from the
shell manually "Changing password for user." is the first thing printed
to the console. So, here's my questions:

1. Why does my readline come last?
2. Also, when I do more than one readline, I get nothing, why is this?
I should be able to read "New password:" and "Retype new password:"
from the process.
3. Why is my write being ignored?

Jul 18 '05 #1
5 2139
Read this:

http://pexpect.sourceforge.net/#faq

Then you most probably want to use it :)

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Diez B. Roggisch wrote:
Read this:

http://pexpect.sourceforge.net/#faq

Then you most probably want to use it :)


Thank you. That's exactly what I need.

Jul 18 '05 #3
In article <40**************@hotmail.com>,
Bart Nessux <ba*********@hotmail.com> wrote:
Diez B. Roggisch wrote:
Read this:

http://pexpect.sourceforge.net/#faq

Then you most probably want to use it :)


Thank you. That's exactly what I need.


If you can get your hands on a copy of the February 2004 issue of
*Sys Admin* Magazine <URL: http://www.samag.com/articles/2004/0402/ >,
you'll find a bit of encouragement there to pursue Pexpect.
--

Cameron Laird <cl****@phaseit.net>
Business: http://www.Phaseit.net
Jul 18 '05 #4
Cameron Laird wrote:
In article <40**************@hotmail.com>,
Bart Nessux <ba*********@hotmail.com> wrote:
Diez B. Roggisch wrote:
Read this:

http://pexpect.sourceforge.net/#faq

Then you most probably want to use it :)


Thank you. That's exactly what I need.

If you can get your hands on a copy of the February 2004 issue of
*Sys Admin* Magazine <URL: http://www.samag.com/articles/2004/0402/ >,
you'll find a bit of encouragement there to pursue Pexpect.


After downloading and installing pexpect... this works for me:

import pexpect

password = 'password'
child = pexpect.spawn('/usr/bin/passwd root')
child.expect_exact('New password:')
child.sendline(password)
child.expect_exact('Retype new password:')
child.sendline(password)

Does this look safe? The documentation on the module was lacking. Seems
like I should close the process that was spawned. Any tips?

Jul 18 '05 #5
Bart Nessux wrote:
Cameron Laird wrote:
In article <40**************@hotmail.com>,
Bart Nessux <ba*********@hotmail.com> wrote:
Diez B. Roggisch wrote:

Read this:

http://pexpect.sourceforge.net/#faq

Then you most probably want to use it :)
Thank you. That's exactly what I need.

If you can get your hands on a copy of the February 2004 issue of
*Sys Admin* Magazine <URL: http://www.samag.com/articles/2004/0402/ >,
you'll find a bit of encouragement there to pursue Pexpect.

After downloading and installing pexpect... this works for me:

import pexpect

password = 'password'
child = pexpect.spawn('/usr/bin/passwd root')
child.expect_exact('New password:')
child.sendline(password)
child.expect_exact('Retype new password:')
child.sendline(password)

Does this look safe? The documentation on the module was lacking. Seems
like I should close the process that was spawned. Any tips?


This works 100% on Mac OSX 10.3.2... The time.sleeps had to be added to
make it work consistently.

def set_pass():
# Function to change root passwd on Mac 10.3 systems
import pexpect
import time
set = r"password"
child = pexpect.spawn("/usr/bin/passwd")
child.expect_exact("New password:")
child.sendline(set)
time.sleep(0.1)
child.expect_exact("Retype new password:")
child.sendline(set)
time.sleep(0.1)
child.close()

set_pass()
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
21580
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
9
1951
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
6
10277
by: vladislavf | last post by:
Hi All, I need to pass array of strings from C++/CLI to unmanaged C++ function. (The unmanaged API signatire is : int Combine(int NumOfInputFiles, wchar_t **names) and I want to call it from...
8
1942
by: Merlin | last post by:
Ok.... I feel really dumb on this one, because I had previously figured it out, and now don't have a clue. I'm trying to get the user to input a new filename (via an integer variable) and...
4
1997
by: Kza | last post by:
Hi, just in the process of maintaining some software that used some funy old string library and char*s , and we are updating everything to use std::strings. (or should I say std::basic_string<>s) ...
5
10139
by: cpnet | last post by:
I'm able to pass string parameters with no problems to a LocalReport being displayed by the ASP.NET ReportViewer control. However, my report also has a DateTime parameter. ...
14
4799
by: Siegfried Heintze | last post by:
Why does VB.NET V2 force me to pass by value for my set function? When I try to change it to const byref it gives me a syntax error. It seems very inefficient to be passing strings around by value...
2
3073
by: pabs1111 | last post by:
Hi All I think I have made a very newbie mistake in my use of Pass Through Queries. I have created pass through queries using the query wizard and then setting the connection string in the...
9
1828
by: sparks | last post by:
Right now I had to build a report that allowed the people to check for gross outliers in their data input. short I am looking at 2.5* std dev + - anyway I used 2 dummy variables in the query the...
14
3642
by: randysimes | last post by:
I am having a user enter two strings: user, password. I then have to pass these two strings to a class function that accepts const char* for user and char* for password. How would I convert the...
0
7157
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
7192
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...
1
6862
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...
0
5452
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
4579
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
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 ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
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...

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.