Community

..someday std.process would have a system call that would return the output of
a std.process.system() call. Yes, I know I could pipe it a file and read the
file. But perl has this beautiful thing,
@text = `somecmd opt1 opt2 etc`;
where the array @text now has all the output caused by the execution of
somecmd opt1 opt2 etc
there is no need to open a file or anything. It's already there. Oh, by the
way, I am not saying that it should be system, but something more like
char[][] systemOut()
instead of returning the always ambiguous int. :-)
Anyone agrees? Or am I just in right field behind the first baseman?
thanks.
josé

jicman wrote:
> I am not saying that it should be system, but something more like
>
> char[][] systemOut()
>
> instead of returning the always ambiguous int. :-)
>
> Anyone agrees? Or am I just in right field behind the first baseman?
Why char[][] and not char[]? How would you get the exit value of the
process without the int return? What if you wanted to grab a stream
other than stdout? I think a more generic solution would be better, but
then I personally don't really need to use this feature that much.

I posted a popen implementation a bit earlier on.
news://news.digitalmars.com:119/cscp40$pee$1@digitaldaemon.comhttp://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/14470
I think this is like... close to what you want. It allows you to read
from the popen (Linux or Windows) as if it were a file. Without the
intermediate temporary file ;).
Any function that returned a string or array thereof would use something
like this, likely, I would think.
-[Unknown]
> ..someday std.process would have a system call that would return the output of
> a std.process.system() call. Yes, I know I could pipe it a file and read the
> file. But perl has this beautiful thing,
>
> @text = `somecmd opt1 opt2 etc`;
>
> where the array @text now has all the output caused by the execution of
>
> somecmd opt1 opt2 etc
>
> there is no need to open a file or anything. It's already there. Oh, by the
> way, I am not saying that it should be system, but something more like
>
> char[][] systemOut()
>
> instead of returning the always ambiguous int. :-)
>
> Anyone agrees? Or am I just in right field behind the first baseman?
>
> thanks.
>
> josé
>
>

Niall FitzGibbon says...
>
>jicman wrote:
>> I am not saying that it should be system, but something more like
>>
>> char[][] systemOut()
>>
>> instead of returning the always ambiguous int. :-)
>>
>> Anyone agrees? Or am I just in right field behind the first baseman?
>
>Why char[][] and not char[]?
Hey, I take either. The reason why char[][] is better is that I have everything
broken down in lines, for me. There is no more
char[][] s = split(str,"\n\r");
But instead a beautiful foreach loop would give me all the lines. :-)
>How would you get the exit value of the
>process without the int return?
That is the reason for the new add (systemOut) or whatever Walter wants. I am
not picky. If you want the int return value then use the actual system() call.
I very seldom care for the return, but more for the output. It gives me
information, plus it tells me if it worked or not. If I ever need to get the
int return, then I'd just use the now resident system function.
> What if you wanted to grab a stream other than stdout?
Good question, my friend. Perhaps, systemErr() is in order. ;-)
> I think a more generic solution would be better, but
>then I personally don't really need to use this feature that much.
Then, sorry to say it, but why even ask those questions? A nice yes or no would
suffice. ;-) Just kidding man, but this is one of the reasons why this is
getting a little too much bandwidth. If you didn't care, then why provoke with
the questions? Sorry, but... ;-)
josé

Unknown,
this would work. I hadn't noticed this. Still, though, a systemOut() also be
nice.
thanks.
Is there any way that you can zip this and attach it again? I don't want to
copy and paste it and I am using the web browser and not the news reader.
thanks again.
jic
Unknown W. Brackets says...
>
>I posted a popen implementation a bit earlier on.
>
>news://news.digitalmars.com:119/cscp40$pee$1@digitaldaemon.com
>http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/14470
>
>I think this is like... close to what you want. It allows you to read
>from the popen (Linux or Windows) as if it were a file. Without the
>intermediate temporary file ;).
>
>Any function that returned a string or array thereof would use something
>like this, likely, I would think.
>
>-[Unknown]
>
>
>> ..someday std.process would have a system call that would return the output of
>> a std.process.system() call. Yes, I know I could pipe it a file and read the
>> file. But perl has this beautiful thing,
>>
>> @text = `somecmd opt1 opt2 etc`;
>>
>> where the array @text now has all the output caused by the execution of
>>
>> somecmd opt1 opt2 etc
>>
>> there is no need to open a file or anything. It's already there. Oh, by the
>> way, I am not saying that it should be system, but something more like
>>
>> char[][] systemOut()
>>
>> instead of returning the always ambiguous int. :-)
>>
>> Anyone agrees? Or am I just in right field behind the first baseman?
>>
>> thanks.
>>
>> josé
>>
>>

jicman wrote:
> Then, sorry to say it, but why even ask those questions? A nice yes or no would
> suffice. ;-) Just kidding man, but this is one of the reasons why this is
> getting a little too much bandwidth. If you didn't care, then why provoke with
> the questions? Sorry, but... ;-)
Just interested, that's all. Sorry if my post seemed confrontational or
unnecessary :)
I think such a feature would be good, but as I said I think it would be
nicer to be able to retrieve the exit value *and* the stream output(s)
with a single call -- in some situations there would be a need for both.
How about just an overload of the existing function?
int system(char[] command, out char[] stdOut, out char[] stdErr)

Niall FitzGibbon says...
>
>jicman wrote:
>
>> Then, sorry to say it, but why even ask those questions? A nice yes or no would
>> suffice. ;-) Just kidding man, but this is one of the reasons why this is
>> getting a little too much bandwidth. If you didn't care, then why provoke with
>> the questions? Sorry, but... ;-)
>
>Just interested, that's all. Sorry if my post seemed confrontational or
> unnecessary :)
It was not. I was just kidding... If you haven't figured it by now, I'm a
kidder. :-)
>I think such a feature would be good, but as I said I think it would be
>nicer to be able to retrieve the exit value *and* the stream output(s)
>with a single call -- in some situations there would be a need for both.
>
>How about just an overload of the existing function?
>
>int system(char[] command, out char[] stdOut, out char[] stdErr)
This would be perfect, man. Perfect indeed. Now, if I could just convince
Walter and the rest of the gang, I'll be in good shape.
jic

On Sun, 13 Mar 2005 21:49:35 +0000, Niall FitzGibbon wrote:
> jicman wrote:
>
>> Then, sorry to say it, but why even ask those questions? A nice yes or no would
>> suffice. ;-) Just kidding man, but this is one of the reasons why this is
>> getting a little too much bandwidth. If you didn't care, then why provoke with
>> the questions? Sorry, but... ;-)
>
> Just interested, that's all. Sorry if my post seemed confrontational or
> unnecessary :)
>
> I think such a feature would be good, but as I said I think it would be
> nicer to be able to retrieve the exit value *and* the stream output(s)
> with a single call -- in some situations there would be a need for both.
>
> How about just an overload of the existing function?
>
> int system(char[] command, out char[] stdOut, out char[] stdErr)
Now that would be a nice routine!
It would simplify the process of capturing output to the point where it
would be a trivial exercise, and thus more people would bother to
incorporate it into their application design.
I know I could use it in Build ;-)
--
Derek Parnell
Melbourne, Australia
http://www.dsource.org/projects/build
14/03/2005 9:27:47 AM