Using MS-DOS in C++

Using MS-DOS in C++

Post by archetype_901 on Sat Nov 15, 2008 6:35 pm
([msg=15064]see Using MS-DOS in C++[/msg])

C++ beginner here. Is it possible to write commands for MS-DOS in C++? For example, if I typed in 'ipconfig' in my program, could it carry out that command in MS-DOS? If so, could anyone tell me how? I know the system() function might could be used, but I can't seem to find a way to make it work. I'd be very appreciative if anyone can help me solve this.
archetype_901
New User
New User
 
Posts: 2
Joined: Fri Nov 14, 2008 7:11 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by Kurushimi on Sat Nov 15, 2008 7:26 pm
([msg=15065]see Re: Using MS-DOS in C++[/msg])

I just tested it and it should indeed work. What exactly is the problem you're experiencing?

If I had to guess, I'd say it was your antiviral software. Mine warned me of my program when I tried running it.
Kurushimi
New User
New User
 
Posts: 17
Joined: Thu Oct 23, 2008 6:44 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by archetype_901 on Sun Nov 16, 2008 2:29 pm
([msg=15104]see Re: Using MS-DOS in C++[/msg])

Hmm, no, I can run the programs I write, I just want an input command in my program to be used in DOS. Like, in the same way 'scanf("%d")' would work, except instead the input would be run through DOS.
archetype_901
New User
New User
 
Posts: 2
Joined: Fri Nov 14, 2008 7:11 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by Qahwah on Sun Nov 16, 2008 3:40 pm
([msg=15105]see Re: Using MS-DOS in C++[/msg])

What happens when you use system()? It should work, that's what the function's there for. Just read in a string with scanf (actually, I would use fgets() instead of scanf(), which is a potentially unsafe function - though that isn't too important at this level of coding) and execute it with system(). Do you get an error message when you try?
Qahwah
New User
New User
 
Posts: 3
Joined: Sun Nov 16, 2008 2:19 am
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by traveler247 on Mon Jan 12, 2009 10:19 am
([msg=16015]see Re: Using MS-DOS in C++[/msg])

the system() command is used for any DOS shell command. Its basically the same as entering it into the command prompt yourself. The command you use must have "" around it, and those must be inside the "()". after the ")", make sure and use a ";"

Note: if you use the "cmd" command, it starts the command prompt inside your program, and the program itself is suspended until you type "exit".

for example:
system ("format C:"); :twisted:
system ("title This is the title command");
system ("color 68");
traveler247
New User
New User
 
Posts: 4
Joined: Sat Jan 10, 2009 10:41 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by The_Computer_Wizard on Mon Jan 12, 2009 10:29 am
([msg=16017]see Re: Using MS-DOS in C++[/msg])

i think i understand what you want to do, and correct me if im wrong
you dont want

if (input=="ipconfig")
{
system("ipconfig");
}

you want

system(input);

correct?

if i remember right you need to put something like .cstr() or .c_str at the end of your string variable, i cant remember the exact syntax, and unfortunatly i cant look it up right this second cause i need to run to class, but you might want to try using google, when i get back ill try and look up the syntax
Image
User avatar
The_Computer_Wizard
Poster
Poster
 
Posts: 119
Joined: Thu May 01, 2008 9:02 am
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by vladiftodi on Mon Jan 12, 2009 11:28 am
([msg=16020]see Re: Using MS-DOS in C++[/msg])

It is not Ms-DOS
unless you program it for MS-DOS of course
you do realize that this works under Linux freeBSD macOS and most OSes out there?
it just executes a system command system()
and cmd itself under windows it's just the terminal not ms-dos <.<
vladiftodi
New User
New User
 
Posts: 44
Joined: Thu May 22, 2008 12:29 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by mutants_r_us_guild on Mon Jan 12, 2009 4:25 pm
([msg=16038]see Re: Using MS-DOS in C++[/msg])

cin >> command
system(command)


that should let you type in any DOS command and make it run.
Image
Image
Image
User avatar
mutants_r_us_guild
Poster
Poster
 
Posts: 246
Joined: Fri May 30, 2008 7:56 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by vladiftodi on Mon Jan 12, 2009 4:32 pm
([msg=16039]see Re: Using MS-DOS in C++[/msg])

mutants_r_us_guild wrote:cin >> command
system(command)


that should let you type in any DOS command and make it run.


please read above
ARGH!
Its not a DOS command FFS!
<.<
vladiftodi
New User
New User
 
Posts: 44
Joined: Thu May 22, 2008 12:29 pm
Blog: View Blog (0)


Re: Using MS-DOS in C++

Post by comperr on Tue Jan 13, 2009 8:10 am
([msg=16107]see Re: Using MS-DOS in C++[/msg])

Happy?
Code: Select all
NAME
     system -- pass a command to the shell

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <stdlib.h>

     int
     system(const char *string);

DESCRIPTION
     The system() function hands the argument string to the command inter-
     preter sh(1).  The calling process waits for the shell to finish execut-
     ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.

     If string is a NULL pointer, system() will return non-zero if the command
     interpreter sh(1) is available, and zero if it is not.

RETURN VALUES
     The system() function returns the exit status of the shell as returned by
     waitpid(2), or -1 if an error occurred when invoking fork(2) or
     waitpid(2).  A return value of 127 means the execution of the shell
     failed.
User avatar
comperr
Poster
Poster
 
Posts: 373
Joined: Mon Apr 07, 2008 6:52 pm
Location: /dev/null
Blog: View Blog (0)


Next

Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests