Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async Process Calls

What is the preferred way of calling other processes asynchronously in D? My use case is calling svn status checking exit status, and parsing its standard output and error.

like image 549
Nordlöw Avatar asked Dec 12 '12 17:12

Nordlöw


People also ask

What is an async call?

An asynchronous method call is a method used in . NET programming that returns to the caller immediately before the completion of its processing and without blocking the calling thread.

What is an async process?

An asynchronous process is a process or function that executes a task "in the background" without the user having to wait for the task to finish.

What is the difference between sync and async call?

Sync is single-thread, so only one operation or program will run at a time. Async is non-blocking, which means it will send multiple requests to a server. Sync is blocking — it will only send the server one request at a time and will wait for that request to be answered by the server.

Is procedure Call synchronous or asynchronous?

Synchronous RPC - Synchronous remote procedure call is a blocking call, i.e. when a client has made a request to the server, the client will wait until it receives a response from the server. Asynchronous RPC - Client makes a RPC call and it waits only for an acknowledgement from the server and not the actual response.


1 Answers

I think std.stdio.popen is what you want:

void popen(string command, in char[] stdioOpenmode = "r");

Use it with a File and you get the output; something like:

File f;
f.popen("svn status", "r");
char[] line;
string result;
while (f.readln(line))
    result ~= line;
return result;

Or you can use std.process.shell which apparently does this for you (and throws an ErrnoException on error).

like image 78
scry Avatar answered Sep 21 '22 13:09

scry