This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes C / C++ and the fly likes Help with c++ and cmd.exe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Help with c++ and cmd.exe" Watch "Help with c++ and cmd.exe" New topic
Author

Help with c++ and cmd.exe

Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
I am attempting to write a shell of sorts for cmd.exe. What I want to do is have the user type in a command and then it be passed into the command line. I know this is possible because freecommander has a way to do this but I need to know how. Any help will be appreciated.


Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

Use the /C option, e.g.
cmd /c dir
executes the "dir" command. For more options type "help cmd" into your shell.
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
i am still somewhat of a newb with c++ so how exactly would i do this? i tried this


and got this error
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

I don't know if we are talking about the same thing here. I understood that you want to pass a command to cmd.exe which gets executed.
Anyway, if you want to execute an external program from within your C code have a look at http://www.cplusplus.com/reference/clibrary/cstdlib/system/
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
thank you soooooo much! that helped out alot! now i just need to figure out how to pass a string to do the same thing.
i used this code:

and got this error:

can you please explain to me why this is happening? also whenever i use:

and put multiple words in the string it only prints out the first word.
any help on this issue?
 
Don't get me started about those stupid light bulbs.
 
subject: Help with c++ and cmd.exe