We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,289 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

System("DATE"): Illegal command error

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;
}
6
Contributors
11
Replies
3 Days
Discussion Span
9 Months Ago
Last Updated
12
Views
billionair
Newbie Poster
9 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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?

Ancient Dragon
Achieved Level 70
Team Colleague
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

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.

_avishek
Light Poster
34 posts since Feb 2010
Reputation Points: 24
Solved Threads: 4
Skill Endorsements: 0

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

Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

Sokurenko
Junior Poster
111 posts since May 2012
Reputation Points: 42
Solved Threads: 13
Skill Endorsements: 0

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.

np complete
Posting Whiz
385 posts since Sep 2010
Reputation Points: 18
Solved Threads: 36
Skill Endorsements: 0

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.

_avishek
Light Poster
34 posts since Feb 2010
Reputation Points: 24
Solved Threads: 4
Skill Endorsements: 0

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

billionair
Newbie Poster
9 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Repost.

billionair
Newbie Poster
9 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

_avishek
Light Poster
34 posts since Feb 2010
Reputation Points: 24
Solved Threads: 4
Skill Endorsements: 0

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.

Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

Ancient Dragon
Achieved Level 70
Team Colleague
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1000 seconds using 2.84MB