| | |
c++ system() function??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
hi, i need help with the system() function.
I need to open up a command line instance, change directory to a certain file, and open a file there. Problem is, every time call the system() function, it calls up a new command line instance. I need to do as i said above, all in a single instance, but cannot figure out how...
Thanks!!!
--Kodiak
I need to open up a command line instance, change directory to a certain file, and open a file there. Problem is, every time call the system() function, it calls up a new command line instance. I need to do as i said above, all in a single instance, but cannot figure out how...
Thanks!!!
--Kodiak
easy!!
this is more of a command shell question though
seperate each command with the & symbol
use a && to ensure that the following command is only run if the previous was successful
so to go up a directory and get the contents
the only difference is that the first version only executes if the initial cd .. executed correctly else it will not continue the second version executes each command no matter what.
BTW a good read http://207.46.196.114/windowsserver/....mspx?mfr=true
this is more of a command shell question though

seperate each command with the & symbol
use a && to ensure that the following command is only run if the previous was successful
so to go up a directory and get the contents
C++ Syntax (Toggle Plain Text)
system("cd .. && DIR"); //or system("cd .. & DIR");
the only difference is that the first version only executes if the initial cd .. executed correctly else it will not continue the second version executes each command no matter what.
BTW a good read http://207.46.196.114/windowsserver/....mspx?mfr=true
Last edited by Killer_Typo; Jul 8th, 2007 at 1:25 am.
Dont forget to spread the reputation to those that deserve!
If you're trying to do
then you're going about it all wrong. Any changes you make inside system() are localised to the sub-process which is created (and then lost almost immediately). The current directory seen by ifstream isn't at the end of the yellow brick road.
If you really want to open a file in another directory, then you need something like
or
But note that chdir() is a concept here, you need to find the actual name of the function which matches your OS/Compiler.
C++ Syntax (Toggle Plain Text)
system( "cd \\the\\yellow\\brick\\road" ); ifstream fin( "lion.txt" );
If you really want to open a file in another directory, then you need something like
C++ Syntax (Toggle Plain Text)
chdir( "\\the\\yellow\\brick\\road" ); ifstream fin( "lion.txt" );
C++ Syntax (Toggle Plain Text)
ifstream fin( "\\the\\yellow\\brick\\road\\lion.txt" );
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi Guys,
I'm having the folowing problem related to the system function.
I want to be able to read from a txt file a string and then launch the string as a bat file. For example, the text file contains "HP DC 7700" and i want to run the bat "HP DC 7700.bat".
I have no ideea on how to pass what I read from the txt to the system function....
Can you help me out?
Thanks and cheers!
I'm having the folowing problem related to the system function.
I want to be able to read from a txt file a string and then launch the string as a bat file. For example, the text file contains "HP DC 7700" and i want to run the bat "HP DC 7700.bat".
I have no ideea on how to pass what I read from the txt to the system function....
Can you help me out?
Thanks and cheers!
•
•
•
•
Hi Guys,
I'm having the folowing problem related to the system function.
I want to be able to read from a txt file a string
•
•
•
•
and then launch the string as a bat file. For example, the text file contains "HP DC 7700" and i want to run the bat "HP DC 7700.bat".
I have no ideea on how to pass what I read from the txt to the system function....
Can you help me out?
Thanks and cheers!
with a C++ string, it would look something like this -
CPP Syntax (Toggle Plain Text)
#include <string> /* ... */ std::string my_string("HP DC 7700.bat"); system( my_string.c_str() ); /* ... */
¿umop apisdn upside down? ![]() |
Similar Threads
- system function in c++ (C++)
- problem with system() function... (C++)
- System function, output to file (C++)
- how to make utilize of system( ) function (C)
- System() Function: Info on uses & Description (C++)
Other Threads in the C++ Forum
- Previous Thread: Pointers Baffled the hell out of me !
- Next Thread: Anagrams
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






