473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

usage of system() function

snehil
19
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 31388
donbock
2,426 Expert 2GB
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 Expert 4TB
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 Expert Mod 8TB
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
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 512MB
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:\\Pr...
Jul 20 '09 #6
system() is prohibited (and dirty) on Windows (see MSDN)
use Shell apis.
Jul 26 '09 #7
Banfa
9,065 Expert Mod 8TB
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
but i still havnt found wat I ws looking for....
Jul 27 '09 #9
lumpybanana247
134 100+
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 "Shortfilename" because it does not contain spaces.
ex. C:\\PROGRA~1\\INTERN~1\\IEXPLORE.EXE
but yes, your code holds the right idea

PS. your header worked fine for me.
Jul 27 '09 #10
snehil
19
thanx.. it worked like a charm.. :)
ok 1 more query...
in this code... IE again opens when i close one window of IE...
is there a code to forcefully open multiple instances of IE window at a same time in an infinite loop... ?
Jul 27 '09 #11
lumpybanana247
134 100+
yes, but it will run so fast that it will make your computer flip in a second. so do not run it without saving all data first. i repeat that: DO NOT RUN IT WITHOUT SAVING ALL DATA
but instead of the system function, i would recommend ShellExecute. it requires <windows.h>
here is an example
ShellExecute( NULL, "open", "C:\\Progra~1\\Intern~1\\IEXPLORE.EXE","","C:\ \", SW_SHOW);
This is much more versatile.
-you do not need to use ShortFileName. Program Files\Internet Explorer works perfectly fine.
-arguments for the program-to-be-run are accepted in the argument i left blank.
-also, you can do SW_SHOW: window is shown; SW_HIDE: window is hidden; etc
Jul 27 '09 #12

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

Similar topics

9
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...
1
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...
1
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...
7
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...
22
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...
16
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...
8
by: bob | last post by:
Which is faster - a call to a system function or a call to a library function?
2
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...
13
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.