Computing.Net > Forums > Programming > DOS commands in C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS commands in C

Reply to Message Icon

Name: mr_cheese
Date: February 7, 2004 at 05:58:29 Pacific
OS: XP
CPU/Ram: 2.6
Comment:

can one run DOS commands using c++. if so whats the command.

thanks for the help



Sponsored Link
Ads by Google

Response Number 1
Name: Infinite Recursion
Date: February 7, 2004 at 07:59:40 Pacific
Reply:

Use a system call to do this...

system("dir");

system("cd mydir");

system("format a:");

system("xcopy *.* c:\mydir");

IR


0

Response Number 2
Name: SN
Date: February 7, 2004 at 08:58:19 Pacific
Reply:

I'm not sure I remember from my C++ days (which are quickly coming back to haunt me since my operating systems class is all C...), but do you need to escape the slash?

c:\\mydir

This question is asked so often that even I have memorized the answer. I would place it at number 3 or 4 in the top 5 questions.
1. Which language should I learn
2. How do I get HTML forms to e-mail to me
3. modify registry with batch
4. use dos commands in C(++)
5. How can I become more like SN?

-SN


0

Response Number 3
Name: mr_cheese
Date: February 7, 2004 at 12:29:33 Pacific
Reply:

i try typing the following but seem to get errors when compiling, im new to C, so if the code is not correct what should i be typing??

___________________________________________
#include <stdlib.h>
#include <process.h>

system()
{
system("echo hello")
}
____________________________________________


0

Response Number 4
Name: SN
Date: February 7, 2004 at 12:44:21 Pacific
Reply:

First off...Always tell us what errors you get when compiling. In this case, a competent C programmer can tell what a few of the errors are without you telling the errors, but it's still polite.

Your system() function should actually be called main...I'm not sure of the exact syntax but it's something like
#include <stdlib.h>
#include <process.h>

int main()
{
system("echo hello")
}

-SN


0

Response Number 5
Name: Fozzie
Date: February 7, 2004 at 20:01:27 Pacific
Reply:

It has been a while hasn't it? ;)

Try:

#include <stdlib.h>
#include <process.h>

int main()
{
system("echo hello");
return 0;
}


0

Related Posts

See More



Response Number 6
Name: mr_cheese
Date: February 8, 2004 at 02:41:05 Pacific
Reply:

thanks for that guys, its all working fine.

can believe i forgot that code :P.

thanks for the help


0

Response Number 7
Name: Infinite Recursion
Date: February 9, 2004 at 05:24:38 Pacific
Reply:

I missed all the glory !?! :(
So SN, how can we become more like you? lol

IR


0

Sponsored Link
Ads by Google
Reply to Message Icon

winsock connect method String in C



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: DOS commands in C

Executing DOS commands in C++ www.computing.net/answers/programming/executing-dos-commands-in-c/6930.html

"TYPE" DOS commands in C www.computing.net/answers/programming/type-dos-commands-in-c-/16874.html

run dos command in vb www.computing.net/answers/programming/run-dos-command-in-vb/121.html