|
-
June 3rd, 2003, 08:51 AM
#1
Execute DOS commands in VC++
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!
-
June 4th, 2003, 01:31 AM
#2
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
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames
-
November 29th, 2007, 08:12 AM
#3
Re: Execute DOS commands in VC++
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)
-
November 29th, 2007, 08:53 AM
#4
Re: Execute DOS commands in VC++
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*
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames
-
November 29th, 2007, 03:41 PM
#5
Re: Execute DOS commands in VC++
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.
-
November 29th, 2007, 05:26 PM
#6
Re: Execute DOS commands in VC++
hey, thnx for responding...
yes, i'm using managed C++
i didn't knew about the function you mentioned, thnx!
-
November 29th, 2007, 09:22 PM
#7
Re: Execute DOS commands in VC++
To delete a file, check out File.Delete in msdn.
-
December 18th, 2007, 06:28 AM
#8
Re: Execute DOS commands in VC++
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)?
-
December 18th, 2007, 10:41 AM
#9
Re: Execute DOS commands in VC++
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|