473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

usage of system() function

snehil
19 New Member
Can I use this code to open Internet explorer if i compile the program file and use the .exe file of the program if yes then pls also tell me the header file..
Expand|Select|Wrap|Line Numbers
  1. system("C:\Program Files\Internet Explorer\IEXPLORE.EXE");
I was trying to make this code but it is not working as I want it to work.. The compiled file displays "Bad command or file name"
Expand|Select|Wrap|Line Numbers
  1. #include<stdlib.h>
  2. void main(void)
  3. {
  4. for(;;)
  5. {
  6. system("C:\Program Files\Internet Explorer\IEXPLORE.EXE");
  7.  
  8. }
  9. }
  10.  
Jul 19 '09 #1
11 31394
donbock
2,426 Recognized Expert Top Contributor
Review the documentation for system. (These are general code hygiene suggestions; they probably won't lead to a solution to your problem.)
  • It has a return value that you should be checking.
  • Consider whether its behavior when passed NULL would be helpful to you.


What happens when you execute your system command string in a Command Prompt window?
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\snehil>  C:\Program Files\Internet Explorer\IEXPLORE.EXE
Jul 19 '09 #2
Markus
6,050 Recognized Expert Expert
It's also possible you'll have to escape your backslashes in the command (you have to do this in other languages I know).

Mark.
Jul 19 '09 #3
Banfa
9,065 Recognized Expert Moderator Expert
It is more than possible, it is necessary. As with many other C like languages in C the character '\' has a special meaning inside a string, it is the escape sequence. Depending on what follows it made have a special meanins, i.e. '\n' is the newline character, '\0' is the zero character (the terminator). If it has no special meaning then it take is ignored '\q' is the character 'q'.

If you want a \ character then you need the sequence '\\'.
Jul 20 '09 #4
snehil
19 New Member
ok.. now the code is
Expand|Select|Wrap|Line Numbers
  1. #include<stdlib.h>
  2. void main(void)
  3. {
  4. for(;;)
  5. {
  6. system("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE");
  7.  
  8. }
  9. }
  10.  
but still the same problem:


and at donbock.. when I execute the command in command prompt
this is the output..



i dont have much knowledge of advanced programing as I am still a beginer...
I saw this code on net and I am just keen to know if it works or not...
from where I saw tyhis code header file was not there so pls also tell if this header file is correct...
bcoz maybe system function is also in process.h m not sure though...
Jul 20 '09 #5
newb16
687 Contributor
There's a thread about 'execute php' at 12 jul. Error message "C:\program is not recognized" gives you a hint - the space is interpreted as a separator, enclose the full file name in quotes. - system("\"C:\\P r...
Jul 20 '09 #6
george666
28 New Member
system() is prohibited (and dirty) on Windows (see MSDN)
use Shell apis.
Jul 26 '09 #7
Banfa
9,065 Recognized Expert Moderator Expert
Also not true.

For Visual C++ 2008, the latest version there are the following pages on the system function

Implemetation Defined Behaviour

system, _wsystem - the actual help on the function

In neither of those 2 places does it say that system is prohibited. Further more Visual C++ 2008 is an ANSI C compliant compiler and to be such it has to fully implement the Standard C Library that includes the system() function.


If you want to make statements like that you need to back them with hard evidence such as a link or quote.
Jul 26 '09 #8
snehil
19 New Member
but i still havnt found wat I ws looking for....
Jul 27 '09 #9
lumpybanana247
134 New Member
yeah, you can launch internet explorer.
your code was about right...


1st. main is supposed to be an int (not void) and should return a number (such as 0).
2nd. a "\" in a string must be written as "\\"
3rd. in many systems (well, mine) you must make the directory into "Shortfilen ame" because it does not contain spaces.
ex. C:\\PROGRA~1\\I NTERN~1\\IEXPLO RE.EXE
but yes, your code holds the right idea

PS. your header worked fine for me.
Jul 27 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4940
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or...
1
2352
by: Randy Jackson | last post by:
I'm attempting to debug some code that uses the System function. When the function is called, it returns Error 1. Does anyone know what that error might be, or where I can find a list of error codes for the function? Any help is most appreciated. -- Randy Jackson http://fourcolorexplosion.com
1
1558
by: praba kar | last post by:
Dear All, In Php If I send a command to system function then It will return 1 on success and 0 on failure. So based upon that value I can to further work. But In Python If I send a command to system function then It will return 0 only for both conditions(success and failure). So What I need to do for this. I want the result like php...
7
1750
by: Harsh_forC | last post by:
hello folks, when i'm using 'System' funtion in TC, perror function is outputting the following error msg..." Not enough memory" wat does it mean? how to get rid of this situaiton? plz help me out!
22
2811
by: SF | last post by:
Hello All, In a windows C learning project I am wokring on I use the system function to run a command, I want to suck the results into a vairable. The system function seems to only return an int. I would like to know how could this is done? I can see only one way currently and I know that there must be a better method. Right now I would be...
16
2134
by: BHARAT MEHTA | last post by:
Hi Guys, I am little new to C. I wish to know the way to use the 'system' function. I mean I know that the function is used to run an external DOS command but every time I use it it returns -1 which meansthe command could not be executed. Kindly help me............
8
3190
by: bob | last post by:
Which is faster - a call to a system function or a call to a library function?
2
2408
by: nnandini8 | last post by:
Hello Guys, I have a doubt in system() function. I need to implement the certain command line arguements in a program. For Example if I type "dnaml" at command line and press enter then it will ask me to enter 'Y' and if I press enter it will generate some files. So here I used system("dnaml")
13
4069
by: Gary Wessle | last post by:
hi how can I use $wc -l file_name which puts out the number of lines. #include <cstdlib> using std::system; system (wc -l file_name) I get ****************************************************************
0
1976
by: rajarora | last post by:
Hi , Is there anybody who have any idea of any System Function in C/C++ for Sun-Solaris (unix) platform which can serve the alternative of execl() system function. Actually I am calling a fork-execl() pair and then making an interprocess communication between these two(parent-child process). But the problem is that somewhere in exec()...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.