472,133 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 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 31265
donbock
2,425 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

Post your reply

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

Similar topics

9 posts views Thread by Penn Markham | last post: by
1 post views Thread by Randy Jackson | last post: by
1 post views Thread by praba kar | last post: by
7 posts views Thread by Harsh_forC | last post: by
16 posts views Thread by BHARAT MEHTA | last post: by
8 posts views Thread by bob | last post: by
2 posts views Thread by nnandini8 | last post: by
13 posts views Thread by Gary Wessle | last post: by
reply views Thread by leo001 | last post: by

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.