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

DOS commands in C

Reply to Message Icon

Original Message
Name: mr_cheese
Date: February 7, 2004 at 05:58:29 Pacific
Subject: DOS commands in C
OS: XP
CPU/Ram: 2.6
Comment:

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

thanks for the help


Report Offensive Message For Removal


Response Number 1
Name: Infinite Recursion
Date: February 7, 2004 at 07:59:40 Pacific
Subject: DOS commands in C
Reply: (edit)

Use a system call to do this...

system("dir");

system("cd mydir");

system("format a:");

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

IR


Report Offensive Follow Up For Removal

Response Number 2
Name: SN
Date: February 7, 2004 at 08:58:19 Pacific
Subject: DOS commands in C
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: mr_cheese
Date: February 7, 2004 at 12:29:33 Pacific
Subject: DOS commands in C
Reply: (edit)

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")
}
____________________________________________


Report Offensive Follow Up For Removal

Response Number 4
Name: SN
Date: February 7, 2004 at 12:44:21 Pacific
Subject: DOS commands in C
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 5
Name: Fozzie
Date: February 7, 2004 at 20:01:27 Pacific
Subject: DOS commands in C
Reply: (edit)

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

Try:

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

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


Report Offensive Follow Up For Removal


Response Number 6
Name: mr_cheese
Date: February 8, 2004 at 02:41:05 Pacific
Subject: DOS commands in C
Reply: (edit)

thanks for that guys, its all working fine.

can believe i forgot that code :P.

thanks for the help


Report Offensive Follow Up For Removal

Response Number 7
Name: Infinite Recursion
Date: February 9, 2004 at 05:24:38 Pacific
Subject: DOS commands in C
Reply: (edit)

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

IR


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: DOS commands in C

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge