opening a batch file
Hi, im relatively new to C++ and recently i have been writing a program that requires the use of a batch file. However, I'm not so sure how i can get the program to run the batch file. I tried using:
system ("C://WINDOWS//system32//cmd.exe C://Documents and Settings//User1//desktop//file.bat");
however that line simply opens up cmd.exe and i want the program to open it up without requiring the user to enter the name of the file.
Can anyone help?
system ("C:/Documents and Settings/User1/desktop/file.bat");
also, you only need to double your slashes when they are backslash( \ ) not forward slashes like above
system only works for .exe and i did do double forwards slashes to replace back-slashes in the above example
>>system only works for .exe
It works for any valid DOS command string.
>>i did do double forwards slashes to replace back-slashes in the above example
No, if it's forward slashes then you don't need double. If it's back-slashes, you need double-backslash. For example:
cout << "//\n/\n\\\n" << flush;
Like a normal DOS command with spaces, you may also have to quote your command:
system ("\"C:/Documents and Settings/User1/desktop/file.bat\"");
im still having trouble. i read all the posts here and put the following into my program
system ("C:\\Documents and Settings\\User 1\\Desktop\\blah.bat")
however it still hasnt run the file blah.bat in my desktop.
The batch file contained the command
which should shutdown my computer. I ran the file to check that it worked and it does. I then checked that i got the path to it right and i did, so why isnt it working?
Because, as anonytmouse has mentioned, you need quotes around the string if there's spaces in it.
system ("\"C:\\Documents and Settings\\User 1\\Desktop\\blah.bat\"")