Is it possible to run a command prompt in D? For example ipconfig?

jazzIIIlove
jazzIIIlove used Ask the Experts™
on
Hi there;

Is it possible to run a command prompt in D? For example ipconfig? I searched for its forums and language specifications and I couldn't find anything regarding.

I mean in C, in stdlib.h, there is the system function doing that job. But where in D?

Best regards...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Author of the Year 2009
Commented:
If you have acces to Windows API functions, then the same techniques as used in C++ should work for you.  Please see:
Execute a Program with C++
http://www.experts-exchange.com/A_1595.html
>>If you have acces to Windows API functions

That I am not sure but the following link says so if I understand it right.
http://www.digitalmars.com/d/2.0/windows.html

I mean which functions and where?  I have a confusion about the term API concept, documentation or what? (Sorry of that illiterate being:)

So, in your work which I find it really helpful, you give examples regarding shellexecute function. In my case, am i going to reimplement a shellexecute function?

By the way, I found out a stdlib.h header file of D. (That I missed before). I attached stdlib.h of both VS 6.0 and the one coming with D. I tried for it to run the process but simply, I couldn't compile it that D gives errors.

Thanks for your interest...I really appreciate...
D-stdlib.txt
C-STDLIB.txt
oh dear, there is a typo in my code. I did it, simply by calling system function stdlib.h. Before concluding question, what do you mean by accessing API functions? I mean could you give more info regarding the API functions?

What if there is no stdlib.h header. What should I do in that case? I mean your article seems it will work regardless of programming language if I have that windows API functions. Am i right? (I am illiterate regarding the issue)

My new issue is reading from a text file. I will try for it. If I fail, I would be asking another question regarding File IO. (I think it's very similar with C, am i right?)

Best regards...and loved your article...
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

For the API concept, I find this while searching for Haskell.

>>The best way to execute an external program without any windows popping up is to use the >>ShellExecuteEx() API function with the "open" verb. If ShellExecuteEx() is available to you in Haskell, >>then you should be able to achieve what you want.

Author of the Year 2009
Commented:
The stdlib.h file that you posted contans the system command.  You should be able to use, for instance:
#include <stdlib.h>
...
system( "notepad.exe" );  // run notepad program
 
As for Shell Eecute... see the "Basic Example" here:
    http://www.dprogramming.com/linkdef.php

import std.string;
import std.c.windows.windows;
 
extern(Windows) HINSTANCE ShellExecuteA(HWND, LPCTSTR,
	LPCTSTR, LPCTSTR, LPCTSTR, INT);
 
int main(char[][] args)
{
	if(args.length < 2) return 1;
	ShellExecuteA(null, "open", toStringz(args[1]), null, null, SW_SHOW);
	return 0;
}

Open in new window

I totally missed that link!
Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial