I know that what i am about to ask is pretty stupidious but...
How can i run a file from within VC++ ?
More specifically i want to delete a file so i want to run
"del myfile.txt" just as if i was in DOS shell
Thanks for reading this!
Printable View
I know that what i am about to ask is pretty stupidious but...
How can i run a file from within VC++ ?
More specifically i want to delete a file so i want to run
"del myfile.txt" just as if i was in DOS shell
Thanks for reading this!
does the system function not work?!
try just this
Code://you must include stdlib.h before this
system("del fname.ext"); //executes tis command in the shell
I see the thread is some years old, but I hope someone will respond..
I have the same question as Logikos, and I tryed SeventhStar's solution (and it works)...
but, if i want to use commands based on variables, like...
system(exec);
where exec is a string, problems arrise (because function system is taking only const char* variables..and mine are System::String)
Any suggestions, plz? (using Visual Studio 2005)
You obviously use managed C++ (.NET).
So why don't you try System.Diagnostics.Process.Start instead of trying to convert System.String to const char*
In general you are usually better off using an api or class that performs the intended functionality rather than using system commands.
Why? Because the former allows you to capture detailed error information whereas the latter does not.
hey, thnx for responding...
yes, i'm using managed C++
i didn't knew about the function you mentioned, thnx!
To delete a file, check out File.Delete in msdn.
me again...
System.Diagnostics.Process.Start works fine, but it has 1 flaw, it's executing files simultaneously...
If the code that's following this function depends on this output, there will be an error
I'm currently using Sleep(10000) (as in sleep for 10 secs), but thats just a workaround.., is there a proper solution to this matter (continue executing code after this function has finished)?
This isn't a flaw in Process.Start because this method is intended to launch a process asynchronously. If you need to launch a process synchronously and read its std output, you need to tell Process.Start to do that.
Check out my response in the C# program calling jar (or .bat) post. It include a code snippet that redirects std output and waits for the process to end.