www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.process.system asynchronous? or win cmd line oddity?

reply "Nick Sabalausky" <a a.a> writes:
Is std.process.system asynchronous? Is it supposed to be? Is execv known to 
trick the windows command-line into giving control back to the user?

I've been playing around a bit (on windows) with rdmd, which uses system() 
heavily (and also execv for running a newly-compiled program), and I 
frequently get text appearing (such as a compiler error message or results 
from a program being rdmd'd and run) *after* I get keyboard control back 
with a new prompt. Which is weird.

It's going to take a little more work to whittle it down to a good test 
case, but I thought I'd ask if anyone knew something already.
Aug 19 2010
next sibling parent "Nick Sabalausky" <a a.a> writes:
"Nick Sabalausky" <a a.a> wrote in message 
news:i4kv18$14qh$1 digitalmars.com...
 Is std.process.system asynchronous? Is it supposed to be? Is execv known 
 to trick the windows command-line into giving control back to the user?

Also, do either of those have any sort of known gotchas regarding redirected stdio/stderr/etc? I'm getting some odd cases of missing text in my editor's cmd-line output window when I'm messing around with rdmd. Not sure if it's just a bug with my editor or not.
 I've been playing around a bit (on windows) with rdmd, which uses system() 
 heavily (and also execv for running a newly-compiled program), and I 
 frequently get text appearing (such as a compiler error message or results 
 from a program being rdmd'd and run) *after* I get keyboard control back 
 with a new prompt. Which is weird.

 It's going to take a little more work to whittle it down to a good test 
 case, but I thought I'd ask if anyone knew something already.
 

Aug 19 2010
prev sibling next sibling parent reply "Nick Sabalausky" <a a.a> writes:
"Nick Sabalausky" <a a.a> wrote in message 
news:i4kv18$14qh$1 digitalmars.com...
 Is execv known to
 trick the windows command-line into giving control back to the user?

Ok that seems to be the case. See the attached screenshot. But it works fine on Linux though (assuming you add the proper "./", of course). Something else interesting to note for anyone who didn't already know (like me), is that if you change the body of execA's main to: write("In A"); // Note this doesn't automatically flush system("execB"); Then the output is backwards (on either Windows or Linux): In B In A
Aug 19 2010
next sibling parent reply Kagamin <spam here.lot> writes:
Nick Sabalausky Wrote:

 Is execv known to
 trick the windows command-line into giving control back to the user?


Trick what into what?
 Ok that seems to be the case. See the attached screenshot. But it works fine 
 on Linux though (assuming you add the proper "./", of course).
 
 Something else interesting to note for anyone who didn't already know (like 
 me), is that if you change the body of execA's main to:
 
 write("In A"); // Note this doesn't automatically flush
 system("execB");
 

Aug 20 2010
parent reply "Nick Sabalausky" <a a.a> writes:
"Kagamin" <spam here.lot> wrote in message 
news:i4mfpe$2cjk$1 digitalmars.com...
 Nick Sabalausky Wrote:

 Is execv known to
 trick the windows command-line into giving control back to the user?


Trick what into what?

See the screenshot I attached to that post. That should clarify what I mean.
 Anyway, console output is broken in phobos.

In what way?
 Did you know, windows console supports unix-style line breaks?

If you mean that it'll output either "\r\n" or just "\n" as a newline, then yes. I've always been happy about that :)
Aug 20 2010
parent Kagamin <spam here.lot> writes:
Nick Sabalausky Wrote:

 Anyway, console output is broken in phobos.

In what way?

http://d.puremagic.com/issues/show_bug.cgi?id=2742
Aug 20 2010
prev sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 20 Aug 2010 02:48:51 -0400, Nick Sabalausky <a a.a> wrote:

 "Nick Sabalausky" <a a.a> wrote in message
 news:i4kv18$14qh$1 digitalmars.com...
 Is execv known to
 trick the windows command-line into giving control back to the user?

Ok that seems to be the case. See the attached screenshot. But it works fine on Linux though (assuming you add the proper "./", of course).

std.process.system simply calls the standard C system function. So whatever Windows does with that is the same as when you call the D version.
 Something else interesting to note for anyone who didn't already know  
 (like
 me), is that if you change the body of execA's main to:

 write("In A"); // Note this doesn't automatically flush
 system("execB");

 Then the output is backwards (on either Windows or Linux):

 In B
 In A

phobos I/O is built on top of the C I/O model, which auto-flushes after newlines (I think only on consoles, but I'm not sure). -Steve
Aug 23 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 8/23/10 5:14 CDT, Steven Schveighoffer wrote:
 On Fri, 20 Aug 2010 02:48:51 -0400, Nick Sabalausky <a a.a> wrote:

 "Nick Sabalausky" <a a.a> wrote in message
 news:i4kv18$14qh$1 digitalmars.com...
 Is execv known to
 trick the windows command-line into giving control back to the user?

Ok that seems to be the case. See the attached screenshot. But it works fine on Linux though (assuming you add the proper "./", of course).

std.process.system simply calls the standard C system function. So whatever Windows does with that is the same as when you call the D version.
 Something else interesting to note for anyone who didn't already know
 (like
 me), is that if you change the body of execA's main to:

 write("In A"); // Note this doesn't automatically flush
 system("execB");

 Then the output is backwards (on either Windows or Linux):

 In B
 In A

phobos I/O is built on top of the C I/O model, which auto-flushes after newlines (I think only on consoles, but I'm not sure).

Yes, to the best of my knowledge auto-flushing upon \n happens only if isatty() is true. Andrei
Aug 23 2010
prev sibling parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Thursday 19 August 2010 21:07:30 Nick Sabalausky wrote:
 Is std.process.system asynchronous? Is it supposed to be? Is execv known to
 trick the windows command-line into giving control back to the user?
 
 I've been playing around a bit (on windows) with rdmd, which uses system()
 heavily (and also execv for running a newly-compiled program), and I
 frequently get text appearing (such as a compiler error message or results
 from a program being rdmd'd and run) *after* I get keyboard control back
 with a new prompt. Which is weird.
 
 It's going to take a little more work to whittle it down to a good test
 case, but I thought I'd ask if anyone knew something already.

I believe that I got some odd behavior when I used wget; IIRC, it was returning before wget actually did anything. I ended up having to use curl. I still don't know how that happened, since even if wget started a new thread, I wouldn't have expected it to terminate and return from system. Maybe it starts a new process. I don't know. But I have seen weird behavior from system before. I don't know how much of it has to do with system and how much of it has to do with the programs themselves though. - Jonathan M Davis
Aug 20 2010