12 Replies - 44873 Views - Last Post: 20 July 2009 - 07:33 AM Rate Topic: -----

#4 tazirul   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 20-July 06

Re: code for runing dos commands in c

Posted 21 July 2006 - 12:00 AM

#include<stdio.h>
#include<process.h>//reqd. for system function prototype
main()
{
system(Dos command);/*In dos commands write the apropriate comand but it should be in windows\system32\*/
return 0;
}


This post has been edited by Dark_Nexus: 21 July 2006 - 12:08 AM

Was This Post Helpful? 1

#5 dorknexus   User is offline

  • or something bad...real bad.
  • member icon

Reputation: 1272
  • View blog
  • Posts: 4,625
  • Joined: 02-May 04

Re: code for runing dos commands in c

Posted 21 July 2006 - 12:09 AM

first of all i'd like to say, "welcome to dream in code!!" now let's get down to business. this post doesn't seem to have much of a purpose. are you asking a question? are you informing the community of this? i am not quite sure what you are trying to do here.
Was This Post Helpful? 0
  • +
  • -

#6 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: code for runing dos commands in c

Posted 21 July 2006 - 12:19 AM

Seems like you are trying to inform people about it.
In that case please post this code in the Code Snippets Section.

To Mods : Looks like new Members never seem to read the rules before they post.
Was This Post Helpful? 0
  • +
  • -

#7 Mrafcho001   User is offline

  • D.I.C Addict
  • member icon

Reputation: 41
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: code for runing dos commands in c

Posted 21 July 2006 - 12:37 PM

Although this may work on most system some systems might not have the system command. And this will only work on Windows.

And this is kind of a pointless post...
Was This Post Helpful? 0
  • +
  • -

#8 dorknexus   User is offline

  • or something bad...real bad.
  • member icon

Reputation: 1272
  • View blog
  • Posts: 4,625
  • Joined: 02-May 04

Re: code for runing dos commands in c

Posted 21 July 2006 - 01:14 PM

hence the name of the topic
Was This Post Helpful? 0
  • +
  • -

#9 kaustubh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-March 07

Re: code for runing dos commands in c

Posted 13 March 2007 - 06:18 AM

hi this is kaustubh

iwant to implement DOS commands (copy rename paste dir/p etc etc) using C language.
Plz help me
Was This Post Helpful? 0
  • +
  • -

#10 ajwsurfer   User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 376
  • Joined: 24-October 06

Re: code for runing dos commands in c

Posted 13 March 2007 - 10:01 AM

http://www.cplusplus...lib/system.html
;)
Was This Post Helpful? 0
  • +
  • -

#11 chiru_ach   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-July 09

Re: code for runing dos commands in c

Posted 19 July 2009 - 10:31 PM

View Posttazirul, on 20 Jul, 2006 - 11:00 PM, said:

#include<stdio.h>
#include<process.h>//reqd. for system function prototype
main()
{
system(Dos command);/*In dos commands write the apropriate comand but it should be in windows\system32\*/
return 0;
}


In this code system function execute[code] correctly. But In c++ how to execute dos commands.
Was This Post Helpful? 0
  • +
  • -

#12 Ancient Dragon   User is offline

  • D.I.C Addict
  • member icon

Reputation: 82
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: code for runing dos commands in c

Posted 19 July 2009 - 10:34 PM

>>In this code system function execute[ code ] correctly. But In c++ how to execute dos commands.

Its done the same way


std::string command = "dir /s";
system(command.c_str());


This post has been edited by Ancient Dragon: 19 July 2009 - 10:37 PM

Was This Post Helpful? 0
  • +
  • -

#13 jeff666   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 193
  • Joined: 30-December 08

Re: code for runing dos commands in c

Posted 20 July 2009 - 06:44 AM

system() must never be used in Windows (see MSDN)
Use standard apis like CreateProcess()
(and "DOS" doesn't exist any more for years..)

This post has been edited by jeff666: 20 July 2009 - 06:45 AM

Was This Post Helpful? 0
  • +
  • -

#14 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: code for runing dos commands in c

Posted 20 July 2009 - 07:02 AM

What is your MSDN reference for this? As far as I can tell system() works in windows and has been used for years and years. They even have a special "_wsystem()" for use with unicode.

So if you have a reference I would love to see it.

On the other hand, if one is working with a "windows GUI" program I would highly recommend using CreateProcess() over system(). as system() will use cmd.exe to execute its command. This results in a nice command window being created and who wants that?

but I really throw the BS flag on

Quote

system() must never be used in Windows (see MSDN)

Was This Post Helpful? 0
  • +
  • -

#15 Ancient Dragon   User is offline

  • D.I.C Addict
  • member icon

Reputation: 82
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: code for runing dos commands in c

Posted 20 July 2009 - 07:18 AM

I have never seen a reference in MSDN which stated that system() should never be used. But a lot of programmers claim that calling system() can open up the program to virus attacks because someone could replace cmd.exe with something else. My response to that: if someone did that then the computer has a lot bigger problems than my program!
Was This Post Helpful? 0
  • +
  • -

#16 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: code for runing dos commands in c

Posted 20 July 2009 - 07:33 AM

Well making system calls is generally not a great idea, most beginners do it for things like "CLS", "color", "pause" and I understand why -- its simple and get the job done, and none of those things are intuitive or simple if you do them right. SO I personally don't mind seeing this done in beginner programs but I think that in a professional program such a thing would be a sign of poor/lazy programming.

Quote

someone could replace cmd.exe with something else... if someone did that then the computer has a lot bigger problems than my program!
I agree. Generally one would use the system calls for legitimate reasons like running system administration scripts (I am not going to rewrite net.exe or netstat.exe just so that I can avoid system()) -- if there is a problem with net.exe or netstat.exe or cmd.exe then it really is not my problem -- the computer needs help. Its no more of a risk than a system administrator going to the command prompt to run those tools.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1