delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/29/19:13:02

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <008901c1d77f$847baa40$5b46fea9@mchasecompaq>
From: "Michael A Chase" <mchase AT ix DOT netcom DOT com>
To: "Brian Warn" <bwarn-nm AT seattletimes DOT com>, <cygwin AT cygwin DOT com>
References: <D4AE310621B50E4393EFE060F52D414CA886C9 AT EXCHANGE2 DOT seatimes DOT com>
Subject: Re: ps within DOS
Date: Fri, 29 Mar 2002 16:11:50 -0800
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

----- Original Message -----
From: "Brian Warn" <bwarn-nm AT seattletimes DOT com>
To: <cygwin AT cygwin DOT com>
Sent: Friday, March 29, 2002 14:55
Subject: RE: ps within DOS


> I suppose that I could run this under cygwin's perl ...

It would certainly be easier if you aren't mixing environment when you don't
have to.
More below.

> From: Brian Warn [mailto:bwarn-nm AT seattletimes DOT com]
> Sent: Friday, March 29, 2002 2:54 PM
> To: 'cygwin AT cygwin DOT com'
> Subject: ps within DOS
>
>
> As part of a (win32) perl program I'm running, I'm trying to run a
> system ps command and return to the DOS shell (or whatever the shell is
> known as in Win2K).  From the command line, I can do the following, but
> I stay in the bash shell:
>
> C:> c:\cygwin\cygwin.bat | ps | exit

You are starting an interactive shell, starting ps.exe, starting 'exit', all
under MSDOS and having MSDOS tie each STDIN to the predecessor's STDOUT.

> [ ps info here ]
>
> my_machine $
>
> The bottom line is that I want to read process info into an array as
> follows:
>
> @my_array=`cygwin.bat | ps | grep "desired string"`;

You should use Perl's grep.  If you are using Cygwin ps, you also need '-W'
to see Windows processes (run 'ps -h' for a list of options).  I'd do
something this (TMTOWTDI):

# /usr/bin/perl -w
# This works regardless for both Cygwin Perl and Native Perl
use strict;
open( PS, "ps -W |" ) or die "Pipe from ps failed, $!\n";
my @my_array = grep { /desired string/ } <PS>;
close PS or die "Error from ps, $!\n";
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019