Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4611 > unrolled thread

redirect stdout and stderr to PHP variables?

Started bycrankypuss <no@email.thanks>
First post2012-01-25 12:47 -0700
Last post2012-02-01 05:22 -0700
Articles 16 on this page of 36 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-25 12:47 -0700
    Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-25 22:42 +0100
    Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-25 22:46 +0100
      Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-25 15:53 -0700
        Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 01:33 -0700
          Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-26 09:46 +0100
            Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 02:23 -0700
              Re: redirect stdout and stderr to PHP variables? Michael Fesser <netizen@gmx.de> - 2012-01-26 14:35 +0100
              Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-26 07:49 -0600
          Re: redirect stdout and stderr to PHP variables? Tim Streater <timstreater@greenbee.net> - 2012-01-26 09:00 +0000
            Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 02:27 -0700
              Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-26 11:43 +0100
                Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 04:14 -0700
                  Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-26 13:25 +0100
                    Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-26 07:11 -0700
                      Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-26 16:18 +0100
                        Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:11 -0700
    Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-25 17:25 -0500
      Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:16 -0700
        Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-27 08:49 -0500
          Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-27 16:00 +0100
            Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-27 10:12 -0500
              Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-27 10:37 -0600
                Re: redirect stdout and stderr to PHP variables? Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-30 21:37 -0500
              Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-28 05:00 -0700
    Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-25 16:52 -0600
      Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:22 -0700
        Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-27 12:25 +0100
          Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-28 05:03 -0700
            Re: redirect stdout and stderr to PHP variables? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-01-28 11:40 -0600
            Re: redirect stdout and stderr to PHP variables? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-29 00:40 +0100
    Re: redirect stdout and stderr to PHP variables? Curtis Dyer <dyer85@gmail.com> - 2012-01-25 22:56 +0000
      Re: redirect stdout and stderr to PHP variables? crankypuss <no@email.thanks> - 2012-01-27 03:23 -0700
        Re: redirect stdout and stderr to PHP variables? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-01-27 11:42 +0100
          Re: redirect stdout and stderr to PHP variables? Curtis Dyer <dyer85@gmail.com> - 2012-01-29 04:56 +0000
    Re: redirect stdout and stderr to PHP variables? [solved] crankypuss <no@email.thanks> - 2012-02-01 05:22 -0700

Page 2 of 2 — ← Prev page 1 [2]


#4640

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-01-27 16:00 +0100
Message-ID<4f22bc0a$0$6952$e4fe514c@news2.news.xs4all.nl>
In reply to#4639
On 1/27/2012 2:49 PM, Jerry Stuckle wrote:
> On 1/27/2012 5:16 AM, crankypuss wrote:
>> On 01/25/2012 03:25 PM, Jerry Stuckle wrote:
>>> On 1/25/2012 2:47 PM, crankypuss wrote:
>>>> I'm sure there's a way to do this, probably some simple syntax I've not
>>>> run into and am too stupid to find in the manual or through
>>>> google-fu or
>>>> otherwise.
>>>>
>>>> I'd like to issue an arbitrary shell command in a subroutine and
>>>> have it
>>>> return an array that contains one element representing stdout and
>>>> another element representing stderr.
>>>>
>>>> For example, using tar to deal with a bazillion files, error messages
>>>> might not be seen when specifying verbose output; I'd like to collect
>>>> them and display after stdout.
>>>>
>>>> I've not found any syntax, yet, for redirecting to a PHP variable
>>>> rather
>>>> than some file.
>>>>
>>>> tia.
>>>
>>> Take a look at the proc_open(). The examples show how do return stdout
>>> and stderr in separate streams.
>>
>> Thanks Jerry, someone else mentioned that too, and it looks like it will
>> probably do the trick though I'm not sure how soon I'll be able to play
>> with it.
>>
>>> It may be more than you need (this is made to be interactive between the
>>> PHP script and the process), but you don't HAVE to send data to the
>>> process.
>>
>> I've never minded putting large amounts of effort into building
>> something with a simple general purpose interface, those efforts tend to
>> repay tenfold.
>>
>> (On a personal note, haven't you retired yet? Or are you like me,
>> addicted to code for life?)
>
> Nope, still too young to retire. I don't know what I'd do with myself :)
>

Get a hobby, like computer programming. ;-)

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#4641

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-01-27 10:12 -0500
Message-ID<jfuesc$m1a$1@dont-email.me>
In reply to#4640
On 1/27/2012 10:00 AM, Erwin Moller wrote:
> On 1/27/2012 2:49 PM, Jerry Stuckle wrote:
>> On 1/27/2012 5:16 AM, crankypuss wrote:
>>> On 01/25/2012 03:25 PM, Jerry Stuckle wrote:
>>>> On 1/25/2012 2:47 PM, crankypuss wrote:
>>>>> I'm sure there's a way to do this, probably some simple syntax I've
>>>>> not
>>>>> run into and am too stupid to find in the manual or through
>>>>> google-fu or
>>>>> otherwise.
>>>>>
>>>>> I'd like to issue an arbitrary shell command in a subroutine and
>>>>> have it
>>>>> return an array that contains one element representing stdout and
>>>>> another element representing stderr.
>>>>>
>>>>> For example, using tar to deal with a bazillion files, error messages
>>>>> might not be seen when specifying verbose output; I'd like to collect
>>>>> them and display after stdout.
>>>>>
>>>>> I've not found any syntax, yet, for redirecting to a PHP variable
>>>>> rather
>>>>> than some file.
>>>>>
>>>>> tia.
>>>>
>>>> Take a look at the proc_open(). The examples show how do return stdout
>>>> and stderr in separate streams.
>>>
>>> Thanks Jerry, someone else mentioned that too, and it looks like it will
>>> probably do the trick though I'm not sure how soon I'll be able to play
>>> with it.
>>>
>>>> It may be more than you need (this is made to be interactive between
>>>> the
>>>> PHP script and the process), but you don't HAVE to send data to the
>>>> process.
>>>
>>> I've never minded putting large amounts of effort into building
>>> something with a simple general purpose interface, those efforts tend to
>>> repay tenfold.
>>>
>>> (On a personal note, haven't you retired yet? Or are you like me,
>>> addicted to code for life?)
>>
>> Nope, still too young to retire. I don't know what I'd do with myself :)
>>
>
> Get a hobby, like computer programming. ;-)
>
> Regards,
> Erwin Moller
>

ROFL!

Ah, that's part of the problem, Erwin.  I have a hobby.  But around 
here, airplane rental is $140/hr and up.

Maybe what I need is a cheaper hobby :)

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#4642

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-01-27 10:37 -0600
Message-ID<slrnji5kmb.51n.hellsop@nibelheim.ninehells.com>
In reply to#4641
On Fri, 27 Jan 2012 10:12:08 -0500, Jerry Stuckle wrote:
> On 1/27/2012 10:00 AM, Erwin Moller wrote:
>> Get a hobby, like computer programming. ;-)
>>
>> Regards,
>> Erwin Moller
>>
>
> ROFL!
>
> Ah, that's part of the problem, Erwin.  I have a hobby.  But around 
> here, airplane rental is $140/hr and up.
>
> Maybe what I need is a cheaper hobby :)

100LL ain't cheap either.

-- 
73. I will not agree to let the heroes go free if they win a rigged 
    contest, even though my advisors assure me it is impossible for 
    them to win.
	--Peter Anspach's list of things to do as an Evil Overlord

[toc] | [prev] | [next] | [standalone]


#4689

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-01-30 21:37 -0500
Message-ID<jg7k5d$f71$1@dont-email.me>
In reply to#4642
On 1/27/2012 11:37 AM, Peter H. Coffin wrote:
> On Fri, 27 Jan 2012 10:12:08 -0500, Jerry Stuckle wrote:
>> On 1/27/2012 10:00 AM, Erwin Moller wrote:
>>> Get a hobby, like computer programming. ;-)
>>>
>>> Regards,
>>> Erwin Moller
>>>
>>
>> ROFL!
>>
>> Ah, that's part of the problem, Erwin.  I have a hobby.  But around
>> here, airplane rental is $140/hr and up.
>>
>> Maybe what I need is a cheaper hobby :)
>
> 100LL ain't cheap either.
>

Around $5.30/gal, which is pretty good.  It used to be about 2.5 or 3x 
87 octane unleaded (auto).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#4654

Fromcrankypuss <no@email.thanks>
Date2012-01-28 05:00 -0700
Message-ID<jg0o0c02gfp@news6.newsguy.com>
In reply to#4641
On 01/27/2012 08:12 AM, Jerry Stuckle wrote:
> On 1/27/2012 10:00 AM, Erwin Moller wrote:
>> On 1/27/2012 2:49 PM, Jerry Stuckle wrote:
>>> On 1/27/2012 5:16 AM, crankypuss wrote:
>>>> On 01/25/2012 03:25 PM, Jerry Stuckle wrote:
>>>>> On 1/25/2012 2:47 PM, crankypuss wrote:
>>>>>> I'm sure there's a way to do this, probably some simple syntax I've
>>>>>> not
>>>>>> run into and am too stupid to find in the manual or through
>>>>>> google-fu or
>>>>>> otherwise.
>>>>>>
>>>>>> I'd like to issue an arbitrary shell command in a subroutine and
>>>>>> have it
>>>>>> return an array that contains one element representing stdout and
>>>>>> another element representing stderr.
>>>>>>
>>>>>> For example, using tar to deal with a bazillion files, error messages
>>>>>> might not be seen when specifying verbose output; I'd like to collect
>>>>>> them and display after stdout.
>>>>>>
>>>>>> I've not found any syntax, yet, for redirecting to a PHP variable
>>>>>> rather
>>>>>> than some file.
>>>>>>
>>>>>> tia.
>>>>>
>>>>> Take a look at the proc_open(). The examples show how do return stdout
>>>>> and stderr in separate streams.
>>>>
>>>> Thanks Jerry, someone else mentioned that too, and it looks like it
>>>> will
>>>> probably do the trick though I'm not sure how soon I'll be able to play
>>>> with it.
>>>>
>>>>> It may be more than you need (this is made to be interactive between
>>>>> the
>>>>> PHP script and the process), but you don't HAVE to send data to the
>>>>> process.
>>>>
>>>> I've never minded putting large amounts of effort into building
>>>> something with a simple general purpose interface, those efforts
>>>> tend to
>>>> repay tenfold.
>>>>
>>>> (On a personal note, haven't you retired yet? Or are you like me,
>>>> addicted to code for life?)
>>>
>>> Nope, still too young to retire. I don't know what I'd do with myself :)
>>>
>>
>> Get a hobby, like computer programming. ;-)
>>
>> Regards,
>> Erwin Moller
>>
>
> ROFL!
>
> Ah, that's part of the problem, Erwin. I have a hobby. But around here,
> airplane rental is $140/hr and up.
>
> Maybe what I need is a cheaper hobby :)

LOL, back in college I had a couple roommates who were heavily into 
learning to fly.  I decided that flying was probably a lot like heroin, 
"too good to try".  <g>

[toc] | [prev] | [next] | [standalone]


#4629

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-01-25 16:52 -0600
Message-ID<slrnji11tj.51n.hellsop@nibelheim.ninehells.com>
In reply to#4611
On Wed, 25 Jan 2012 12:47:11 -0700, crankypuss wrote:
> I'm sure there's a way to do this, probably some simple syntax I've not 
> run into and am too stupid to find in the manual or through google-fu or 
> otherwise.
>
> I'd like to issue an arbitrary shell command in a subroutine and have it 
> return an array that contains one element representing stdout and 
> another element representing stderr.
>
> For example, using tar to deal with a bazillion files, error messages 
> might not be seen when specifying verbose output; I'd like to collect 
> them and display after stdout.
>
> I've not found any syntax, yet, for redirecting to a PHP variable rather 
> than some file.

Sorry, you have to use the file, then read the file if you want to parse
back in what went out on stderr. 

-- 
85. I will not use any plan in which the final step is horribly 
    complicated, e.g. "Align the 12 Stones of Power on the sacred altar 
    then activate the medallion at the moment of total eclipse." 
    Instead it will be more along the lines of "Push the button."

[toc] | [prev] | [next] | [standalone]


#4635

Fromcrankypuss <no@email.thanks>
Date2012-01-27 03:22 -0700
Message-ID<jfttst01u66@news1.newsguy.com>
In reply to#4629
On 01/25/2012 03:52 PM, Peter H. Coffin wrote:
> On Wed, 25 Jan 2012 12:47:11 -0700, crankypuss wrote:
>> I'm sure there's a way to do this, probably some simple syntax I've not
>> run into and am too stupid to find in the manual or through google-fu or
>> otherwise.
>>
>> I'd like to issue an arbitrary shell command in a subroutine and have it
>> return an array that contains one element representing stdout and
>> another element representing stderr.
>>
>> For example, using tar to deal with a bazillion files, error messages
>> might not be seen when specifying verbose output; I'd like to collect
>> them and display after stdout.
>>
>> I've not found any syntax, yet, for redirecting to a PHP variable rather
>> than some file.
>
> Sorry, you have to use the file, then read the file if you want to parse
> back in what went out on stderr.

Actually no, I do not have to use no steenking files, I might have to 
start writing something from scratch in freaking assembler, but I don't 
have to use no steenking files to do something that hasn't the least 
thing to do with files.

Thank you though, and apologies for any crankiness that has leaked into 
my post... I'm going through the transition from many years of Windows 
to using Linux, and although I mostly like it, I find the tendency for 
scripts to rely on command output run through pipes to be abhorrent 
since the whole concept of validity checking goes out the window when 
you swallow that paradigm, and writing a file when it isn't necessary to 
the actual process but rather is a matter of conformance to sloppiness 
in the environment is at least as bad imo.

[toc] | [prev] | [next] | [standalone]


#4638

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-01-27 12:25 +0100
Message-ID<9offtcF7hqU1@mid.uni-berlin.de>
In reply to#4635
Am 27.01.2012 11:22, schrieb crankypuss:
> On 01/25/2012 03:52 PM, Peter H. Coffin wrote:
>> On Wed, 25 Jan 2012 12:47:11 -0700, crankypuss wrote:
>>> I'm sure there's a way to do this, probably some simple syntax I've not
>>> run into and am too stupid to find in the manual or through google-fu or
>>> otherwise.
>>>
>>> I'd like to issue an arbitrary shell command in a subroutine and have it
>>> return an array that contains one element representing stdout and
>>> another element representing stderr.
>>>
>>> For example, using tar to deal with a bazillion files, error messages
>>> might not be seen when specifying verbose output; I'd like to collect
>>> them and display after stdout.
>>>
>>> I've not found any syntax, yet, for redirecting to a PHP variable rather
>>> than some file.
>>
>> Sorry, you have to use the file, then read the file if you want to parse
>> back in what went out on stderr.
> 
> Actually no, I do not have to use no steenking files, I might have to start writing
> something from scratch in freaking assembler, but I don't have to use no steenking
> files to do something that hasn't the least thing to do with files.
> 
> Thank you though, and apologies for any crankiness that has leaked into my post...
> I'm going through the transition from many years of Windows to using Linux, and
> although I mostly like it, I find the tendency for scripts to rely on command output
> run through pipes to be abhorrent since the whole concept of validity checking goes
> out the window when you swallow that paradigm, and writing a file when it isn't

Can you expand on that? There must be a misunderstanding, the command you run does
all validity checking, me thinks.

/Str.

> necessary to the actual process but rather is a matter of conformance to sloppiness
> in the environment is at least as bad imo.

[toc] | [prev] | [next] | [standalone]


#4655

Fromcrankypuss <no@email.thanks>
Date2012-01-28 05:03 -0700
Message-ID<jg0o6312gfp@news6.newsguy.com>
In reply to#4638
On 01/27/2012 04:25 AM, M. Strobel wrote:
> Am 27.01.2012 11:22, schrieb crankypuss:
>> On 01/25/2012 03:52 PM, Peter H. Coffin wrote:
>>> On Wed, 25 Jan 2012 12:47:11 -0700, crankypuss wrote:
>>>> I'm sure there's a way to do this, probably some simple syntax I've not
>>>> run into and am too stupid to find in the manual or through google-fu or
>>>> otherwise.
>>>>
>>>> I'd like to issue an arbitrary shell command in a subroutine and have it
>>>> return an array that contains one element representing stdout and
>>>> another element representing stderr.
>>>>
>>>> For example, using tar to deal with a bazillion files, error messages
>>>> might not be seen when specifying verbose output; I'd like to collect
>>>> them and display after stdout.
>>>>
>>>> I've not found any syntax, yet, for redirecting to a PHP variable rather
>>>> than some file.
>>>
>>> Sorry, you have to use the file, then read the file if you want to parse
>>> back in what went out on stderr.
>>
>> Actually no, I do not have to use no steenking files, I might have to start writing
>> something from scratch in freaking assembler, but I don't have to use no steenking
>> files to do something that hasn't the least thing to do with files.
>>
>> Thank you though, and apologies for any crankiness that has leaked into my post...
>> I'm going through the transition from many years of Windows to using Linux, and
>> although I mostly like it, I find the tendency for scripts to rely on command output
>> run through pipes to be abhorrent since the whole concept of validity checking goes
>> out the window when you swallow that paradigm, and writing a file when it isn't
>
> Can you expand on that? There must be a misunderstanding, the command you run does
> all validity checking, me thinks.

Look at any bash script longer than about 4 lines.  You'll find it 
issuing some command and running it through sed or whatever and then 
through the next stage of the pipe and basically *assuming* that command 
output formats never change and nothing can go wrong go wrong.

[toc] | [prev] | [next] | [standalone]


#4658

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-01-28 11:40 -0600
Message-ID<slrnji8coc.51n.hellsop@nibelheim.ninehells.com>
In reply to#4655
On Sat, 28 Jan 2012 05:03:14 -0700, crankypuss wrote:

> On 01/27/2012 04:25 AM, M. Strobel wrote:
>
>> Am 27.01.2012 11:22, schrieb crankypuss:
>>
>>> I'm going through the transition from many years of Windows to
>>> using Linux, and although I mostly like it, I find the tendency for
>>> scripts to rely on command output run through pipes to be abhorrent
>>> since the whole concept of validity checking goes out the window
>>> when you swallow that paradigm, and writing a file when it isn't
>>
>> Can you expand on that? There must be a misunderstanding, the command
>> you run does all validity checking, me thinks.
>
> Look at any bash script longer than about 4 lines. You'll find it
> issuing some command and running it through sed or whatever and then
> through the next stage of the pipe and basically *assuming* that
> command output formats never change and nothing can go wrong go wrong.

That's just how good unix utilties do their work. They never change
output formats except by some kind of request, usually a command option.
The defaults freeze at release, and if there's a different default
output, the utility name will change as well.

-- 
"Every new technology carries with it an opportunity to invent a new
crime." --Laurence Urgenson (an assistant chief US attorney),
speaking in 1987 about the first arrests for what was later called
cellphone cloning.

[toc] | [prev] | [next] | [standalone]


#4667

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-01-29 00:40 +0100
Message-ID<9ojfasFdroU1@mid.uni-berlin.de>
In reply to#4655
Am 28.01.2012 13:03, schrieb crankypuss:
> On 01/27/2012 04:25 AM, M. Strobel wrote:
>> Am 27.01.2012 11:22, schrieb crankypuss:
>>> On 01/25/2012 03:52 PM, Peter H. Coffin wrote:
>>>> On Wed, 25 Jan 2012 12:47:11 -0700, crankypuss wrote:
>>>>> I'm sure there's a way to do this, probably some simple syntax I've not
>>>>> run into and am too stupid to find in the manual or through google-fu or
>>>>> otherwise.
>>>>>
>>>>> I'd like to issue an arbitrary shell command in a subroutine and have it
>>>>> return an array that contains one element representing stdout and
>>>>> another element representing stderr.
>>>>>
>>>>> For example, using tar to deal with a bazillion files, error messages
>>>>> might not be seen when specifying verbose output; I'd like to collect
>>>>> them and display after stdout.
>>>>>
>>>>> I've not found any syntax, yet, for redirecting to a PHP variable rather
>>>>> than some file.
>>>>
>>>> Sorry, you have to use the file, then read the file if you want to parse
>>>> back in what went out on stderr.
>>>
>>> Actually no, I do not have to use no steenking files, I might have to start writing
>>> something from scratch in freaking assembler, but I don't have to use no steenking
>>> files to do something that hasn't the least thing to do with files.
>>>
>>> Thank you though, and apologies for any crankiness that has leaked into my post...
>>> I'm going through the transition from many years of Windows to using Linux, and
>>> although I mostly like it, I find the tendency for scripts to rely on command output
>>> run through pipes to be abhorrent since the whole concept of validity checking goes
>>> out the window when you swallow that paradigm, and writing a file when it isn't
>>
>> Can you expand on that? There must be a misunderstanding, the command you run does
>> all validity checking, me thinks.
> 
> Look at any bash script longer than about 4 lines.  You'll find it issuing some
> command and running it through sed or whatever and then through the next stage of the
> pipe and basically *assuming* that command output formats never change and nothing
> can go wrong go wrong.
> 

It just fits. And no magic, only some basic principles.

/Str.

[toc] | [prev] | [next] | [standalone]


#4630

FromCurtis Dyer <dyer85@gmail.com>
Date2012-01-25 22:56 +0000
Message-ID<jfq1bl$ink$1@dont-email.me>
In reply to#4611
crankypuss <no@email.thanks> wrote:

> I'm sure there's a way to do this, probably some simple syntax
> I've not run into and am too stupid to find in the manual or
> through google-fu or otherwise.
> 
> I'd like to issue an arbitrary shell command in a subroutine and
> have it return an array that contains one element representing
> stdout and another element representing stderr.

Have a look at `proc_open()' for more fine-grained control of a 
process:

  <http://php.net/proc_open>


<snip>

-- 
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>

[toc] | [prev] | [next] | [standalone]


#4636

Fromcrankypuss <no@email.thanks>
Date2012-01-27 03:23 -0700
Message-ID<jfttus11u66@news1.newsguy.com>
In reply to#4630
On 01/25/2012 03:56 PM, Curtis Dyer wrote:
> crankypuss<no@email.thanks>  wrote:
>
>> I'm sure there's a way to do this, probably some simple syntax
>> I've not run into and am too stupid to find in the manual or
>> through google-fu or otherwise.
>>
>> I'd like to issue an arbitrary shell command in a subroutine and
>> have it return an array that contains one element representing
>> stdout and another element representing stderr.
>
> Have a look at `proc_open()' for more fine-grained control of a
> process:
>
>    <http://php.net/proc_open>
>
>
> <snip>

Third recommendation for proc_open() this morning, you guys looking at 
each others' notes? <g>   Thanks.

[toc] | [prev] | [next] | [standalone]


#4637

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-01-27 11:42 +0100
Message-ID<4f227f8b$0$6934$e4fe514c@news2.news.xs4all.nl>
In reply to#4636
On 1/27/2012 11:23 AM, crankypuss wrote:
> On 01/25/2012 03:56 PM, Curtis Dyer wrote:
>> crankypuss<no@email.thanks> wrote:
>>
>>> I'm sure there's a way to do this, probably some simple syntax
>>> I've not run into and am too stupid to find in the manual or
>>> through google-fu or otherwise.
>>>
>>> I'd like to issue an arbitrary shell command in a subroutine and
>>> have it return an array that contains one element representing
>>> stdout and another element representing stderr.
>>
>> Have a look at `proc_open()' for more fine-grained control of a
>> process:
>>
>> <http://php.net/proc_open>
>>
>>
>> <snip>
>
> Third recommendation for proc_open() this morning, you guys looking at
> each others' notes? <g> Thanks.

I was wondering that too.
When I posted my suggestion, I didn't see any others suggesting it.
But today I saw that Jerry and Curtis wrote it one day earlier.
I can imagine I had some mental black-out, but this looks like a mondial 
one. ;-)

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#4669

FromCurtis Dyer <dyer85@gmail.com>
Date2012-01-29 04:56 +0000
Message-ID<jg2jil$giu$1@dont-email.me>
In reply to#4637
Erwin Moller <erwinmollerusenet@xs4all.nl> wrote:

> On 1/27/2012 11:23 AM, crankypuss wrote:
>> On 01/25/2012 03:56 PM, Curtis Dyer wrote:
>>> crankypuss<no@email.thanks> wrote:

<snip>

>>>> I'd like to issue an arbitrary shell command in a subroutine
>>>> and have it return an array that contains one element
>>>> representing stdout and another element representing stderr.
>>>
>>> Have a look at `proc_open()' for more fine-grained control of
>>> a process:
>>>
>>> <http://php.net/proc_open>
>>>
>>>
>>> <snip>
>>
>> Third recommendation for proc_open() this morning, you guys
>> looking at each others' notes? <g> Thanks.
> 
> I was wondering that too.
> When I posted my suggestion, I didn't see any others suggesting
> it. But today I saw that Jerry and Curtis wrote it one day
> earlier. I can imagine I had some mental black-out, but this
> looks like a mondial one. ;-)

In my case, I often get distracted before finishing a post and 
usually end up forgetting to fetch new headers. I suppose it's a 
good sign for the OP when several people agree on an approach.

<snip>

-- 
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>

[toc] | [prev] | [next] | [standalone]


#4705 — Re: redirect stdout and stderr to PHP variables? [solved]

Fromcrankypuss <no@email.thanks>
Date2012-02-01 05:22 -0700
SubjectRe: redirect stdout and stderr to PHP variables? [solved]
Message-ID<jgbaq80bgf@news4.newsguy.com>
In reply to#4611
On 01/25/2012 12:47 PM, crankypuss wrote:
> I'm sure there's a way to do this, probably some simple syntax I've not
> run into and am too stupid to find in the manual or through google-fu or
> otherwise.
>
> I'd like to issue an arbitrary shell command in a subroutine and have it
> return an array that contains one element representing stdout and
> another element representing stderr.
>
> For example, using tar to deal with a bazillion files, error messages
> might not be seen when specifying verbose output; I'd like to collect
> them and display after stdout.
>
> I've not found any syntax, yet, for redirecting to a PHP variable rather
> than some file.
>
> tia.

Thanks for your help, folks.  This seems to do the trick:


// executes $cmd as a separate process and returns the following:
//	$result			= null if unable to start process, else:
//	$result["exit_code"]	= exit code returned by $cmd
//	$result["stdout"]	= stdout written by $cmd
//	$result["stderr"]	= stderr written by $cmd
function sysCmd($cmd)
{
	$result = array();
	$descr = array();
	$descr[0] = array("pipe", "r");		// stdin
	$descr[1] = array("pipe", "w");		// stdout
	$descr[2] = array("pipe", "w");		// stderr
	$proc = proc_open($cmd, $descr, $pipes);
	if (is_resource($proc))
	{
		fclose($pipes[0]);		// no stdin data
		$result["stdout"] = stream_get_contents($pipes[1]);
		fclose($pipes[1]);
		$result["stderr"] = stream_get_contents($pipes[2]);
		fclose($pipes[2]);
		$result["exit_code"] = proc_close($proc);
	}
	return $result;
}

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web