I'm trying to make a C program to run DOS commands but I keep getting "illegal command" error.
Here's the code.

#include<stdio.h>
#include<process.h>

int main()
{
    system("ipconfig/all");
    return 0;
}

go to a command prompt and try that command. BTW your program works ok on Windows 7 using vc++ 2012. What compiler and operating system are you using?

I'm using Linux, so I can't try out DOS commands, but from what I recall both "date" and "ipconfig /all" are valid commands.

Maybe I'm nit-picking here, but the OP's heading makes the question a bit ambiguous as to which command is giving the error.

try it using stdlib header instead of process.h
If you are using windows, then you'll get the desired output!
system("DATE"), system("ipconfig/all") are not illegal commands

this for date ? :) and it should be very portable
Click Here

system() calls should work on windows and works for me. What system call does is, it helps you call all the executable files that are present is C:\Windows\System32. So even calculator, notepad,etc all are valid commands and should work. Atleast in MinGw compilers.

commented: Are you postin usless information just to post? It really seems so. It really helps to read AND UNDERSTAND what has been posted before you post. -3

system("ipconfig/all");

Just a thought, but shouldn't there be a space between the "ipconfig" and the "/all" switch? Possibly that is the cause of the illegal command error.

I would request someone using Windows to cross-check.

I tried again and found that a few commands like "dir" and "cd\" are working. However "ipconfig /all" is still returning the "Illegal command" error. Tried including the stdlib.h header too. Here's the screenshot: http://imgur.com/UyVHp

Repost.

From your screenshot, I see that you are running DOSBOx. DOSBox is an emulator for the old MS-DOS. The wiki page http://www.dosbox.com/wiki/Main_Page clearly states that:

DOSBox also comes with its own DOS-like command prompt. It is still quite rudimentary and lacks many of the features found in MS-DOS, but it is sufficient for installing and running most DOS games.

It is more than likely that DOSBox does not support the "ipconfig" command, which would explain why you are receiving the illegal command error.

Out of curiousity, why are you using DOSBox as a programming environment? It was never designed for such a purpose.

commented: agree +14

Just a thought, but shouldn't there be a space between the "ipconfig" and the "/all" switch?

noo.. theres no need of giving any space.

is ipconfig supported in *nix? Easy way to find out, just try it from a terminal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.