www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to call external program in D

reply "Sparsh Mittal" <sparsh0mittal gmail.com> writes:
I am new to D.

Can you please tell, how to call external program in D.

Example: in C, one can do this: 
http://stackoverflow.com/questions/43116/how-can-i-run-an-external-program-from-c-and-parse-its-output


I want to call an external program (e.g. ls or date) in D.


Thanks
Nov 16 2012
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 16 November 2012 at 19:15:09 UTC, Sparsh Mittal wrote:
 I want to call an external program (e.g. ls or date) in D.

This function should do for many tasks: http://dlang.org/phobos/std_process.html#shell string shell(string cmd); Runs cmd in a shell and returns its standard output. If the process could not be started or exits with an error code, throws an exception. Or maybe this one: http://dlang.org/phobos/std_stdio.html#popen (also search that page for the other popen, which calls the C function without the need for a File struct) Generally, anything you can do in C, you can also do in D by calling the C functions directly.
Nov 16 2012
prev sibling next sibling parent "Sparsh Mittal" <sparsh0mittal gmail.com> writes:
Thanks a lot, it was very helpful.
Nov 16 2012
prev sibling parent =?UTF-8?B?UmFwaGHDq2wgSmFrc2U=?= <raphael.jakse gmail.com> writes:
Le 16/11/2012 20:15, Sparsh Mittal a écrit :
 I am new to D.

 Can you please tell, how to call external program in D.

 Example: in C, one can do this:
 http://stackoverflow.com/questions/43116/how-can-i-run-an-external-program-from-c-and-parse-its-output



 I want to call an external program (e.g. ls or date) in D.


 Thanks

This is out of subject but for ls and date, you might want to get the informations directly in D. See - http://dlang.org/phobos/std_date.html - http://dlang.org/phobos/std_datetime.html - http://dlang.org/phobos/std_file.html#dirEntries
Nov 17 2012