473,809 Members | 2,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

detect suprocess interaction

I'm using subprocess to carry out svn commands (probably should use the svn api
package, but that's a dependency too far). Anyhow my code looks like

from subprocess import Popen, PIPE
p = Popen((svn,'ls' ,u),stdout=PIPE ,stderr=PIPE)
i = p.wait()

and this sort of thing works well under most circumstances. However, when this
code is executed for the very first time by a particular user it hangs waiting
on user input.

This code is being used purely for testing correctness of a particular svn url
so in the normal case we want to throw away both stdout and stderr. In the
exceptional case is it possible to detect that input is required and only in
that case issue the current contents of stdout (presumably a request for a
password)?

Clearly I need to supply some kind of input filelike object, but is this sort of
thing possible.
--
Robin Becker

Mar 23 '07 #1
2 1330
Robin Becker <ro***@reportla b.comwrote:
I'm using subprocess to carry out svn commands (probably should use the svn api
package, but that's a dependency too far). Anyhow my code looks like

from subprocess import Popen, PIPE
p = Popen((svn,'ls' ,u),stdout=PIPE ,stderr=PIPE)
i = p.wait()

and this sort of thing works well under most circumstances. However, when this
code is executed for the very first time by a particular user it hangs waiting
on user input.

This code is being used purely for testing correctness of a particular svn url
so in the normal case we want to throw away both stdout and stderr. In the
exceptional case is it possible to detect that input is required and only in
that case issue the current contents of stdout (presumably a request for a
password)?

Clearly I need to supply some kind of input filelike object, but is this sort of
thing possible.
Yes it is possible, but if you try it you'll find you'll need to
implement the fileno() method of file objects which is asked to return
an OS file handle. This is obviously a problem!

In general subprocess isn't really designed for interactive
processes like the above. You'll find it much easier to use pexpect
for interactive stuff.

Note that svn has its own devious ways of finding a terminal to ask
the user for the password, eg...

$ svn ls svn+ssh://us**@127.0.0.1/svn </dev/null >/dev/null 2>&1
Password:

I don't know exactly how it does that but I suspect it is to do with
the controlling terminal...

On my system

$ setsid svn ls svn+ssh://us**@127.0.0.1/svn </dev/null >/dev/null 2>&1

Pops up a gui box asking for the password!

You can simulate the above with

Popen(..., stdin=file(os.d evnull,"r"), preexec_fn=os.s etsid)

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Mar 26 '07 #2
Nick Craig-Wood wrote:
Robin Becker <ro***@reportla b.comwrote:
> I'm using subprocess to carry out svn commands (probably should use the svn api
..............
>>
Clearly I need to supply some kind of input filelike object, but is this sort of
thing possible.

Yes it is possible, but if you try it you'll find you'll need to
implement the fileno() method of file objects which is asked to return
an OS file handle. This is obviously a problem!
yes I figured I might have to do something low level, but it's not
terribly obvious that I can detect the read at the other end ie normally
we seem to detect when output is available, not when a write is required
ie I might be able to write to the input of my command even if the
command won't read.
In general subprocess isn't really designed for interactive
processes like the above. You'll find it much easier to use pexpect
for interactive stuff.

Note that svn has its own devious ways of finding a terminal to ask
the user for the password, eg...

$ svn ls svn+ssh://us**@127.0.0.1/svn </dev/null >/dev/null 2>&1
Password:

I don't know exactly how it does that but I suspect it is to do with
the controlling terminal...

On my system

$ setsid svn ls svn+ssh://us**@127.0.0.1/svn </dev/null >/dev/null 2>&1

Pops up a gui box asking for the password!

You can simulate the above with

Popen(..., stdin=file(os.d evnull,"r"), preexec_fn=os.s etsid)
......

this just makes life more interesting :)
--
Robin Becker
Mar 26 '07 #3

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

Similar topics

5
8486
by: Quinn | last post by:
When users clicked a unkown mime type link such as Zip on my website, a "Save/Open/Cancel" dialog box pops up. Is there a way to detect which button users clicked by using ASP? actually I only what to record the "valid" click -- when Open/Save was clicked. Thanks ahead. Quinn
3
4130
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: this.TopLevelControl.Cursor = System.Windows.Forms.Cursors.WaitCursor; I also want to prevent user interaction with the controls on my form while the wait cursor is displayed, so that use events (except resize and cancel) are blocked. What is the...
2
6904
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
4
21852
by: vivek | last post by:
I am new to flash and want someone to guide me, Is it possible to create a UI entirely in Flash and that will inetract with C# components (backend) and these components will in return interact with database etc. If flash and C# interaction is possbile then, what are the prons and cons of this interaction? As using flash, one can create wonderful UI. But in return I also want it to interact fully with C# components.
2
1742
by: Alberto | last post by:
How do you write the interaction diagram's messages in c#? like calling a method in the object class? like an event? Thank you
1
1611
by: dwij2u | last post by:
Hi All, Can someone guide me on how we can modify the below script so that no user interaction is required to feed the password when the script is run, current scenario is like if I try to login to a different user from a user other than root it needs user interaction for that, but it should not ask for the user interaction and it should get the password from the script itself. This is the script to modify;and it prompts me for the...
0
2150
by: Omar Abid | last post by:
Reason of this project: The Microsoft.VisualBasic.Interaction class exposes many useful commands and methods that were available in Visual Basic like AppActivate, Beep, Callbyname... This tutorial shows how to work with some of them. Project details: 1- From VB 6.0 to VB .net 2.0 2- Useful interaction commands 3- Samples of interaction commands
10
5830
by: Xu, Qian | last post by:
Hi All, Is it possible to detect whether a (confirmation or prompt) dialog is present? And furthermore, how to press OK, Cancel buttons of a dialog? I am writing a javascript based test framework. I would like to detect and close dialog using javascript. Thanks in advance --
3
3957
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I am fairly happy using IDLE, the debugger is unintuitive to me and I wanted a project manager and a better variable/ class browser and also the potential to edit/run other languages such as R and Tex/Latex. Windows and LINUX compatibility is...
0
9722
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
9603
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,...
0
10378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
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,...
1
7664
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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
5550
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...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
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

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.