C++ Can't call tskill inside with system call - c++

I can't call taskkill or tskill inside VC++ with system i don't know any alternatives, i have tried writing a .bat file and trying calling tskill, that dind't work either.
system("tskill example");
system("dins.bat");
they don't work.
thanks

Use TerminateProcess instead. I also recommend reading this.

Related

C++, Qt: QProcess - How to *avoid* capturing STDOUT

I am looking for a way to start a process and not to capture its STDOUT/STDERR.
I.e. I want the STDOUT/STDERR to be printed directly to the shell, just like in a regular stdlib system() call
Thanks
Yes, you can do this using QProcess::setProcessChannelMode(ProcessChannelMode mode) with argument QProcess::ForwardedChannels. Here is the documentation entry: link
Another option for something equivalent to a stdlib system() call, is QProcess::startDetached() static method. Note that it will not wait for the process to finish, again, like the stdlib system() call

How to run Windows commands in a C++ program?

Is there a way to put windows commands in C++ program.
I am a newbie so your help will be very much appreciated.
Thank You
You can try system function from cstdlib.
http://www.kev.pulo.com.au/pp/RESOURCES/cplusplus/ref/cstdlib/system.html
You should be able to use the system() function from <cstdlib>7. Although be aware that it will probably create a cmd.exe window. If you don't want that then you can use the windows specific CreateProcess() function.

How to Redirect to Another Application in C++?

I've researched it all over StackOverflow and Google but only get results about C# and irrelevant topics, so now I have to ask. I want after 20 seconds of the application being open to close itself and open another application that is in the same folder. After I have debugged, I copy the application to the folder on my Desktop that I will eventually ZIP up. But I want the app to open another application in the folder. Say for instance ApplicationA.exe Opens and after 20 seconds it closes and ApplicationB.exe opens.
You can use the CreateProcess() winapi function which acts like fork()+exec() and then exit() the ApplicationA. Also you can use Sleep(miliseconds) for the delay.
Here is the information about CreateProcess():
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
You can open it with system("ApplicationB.exe"); and then exit. This will start ApplicationB.exe and exit ApplicationA.exe.
Check out: http://www.dreamincode.net/forums/topic/18057-run-external-executable/
I believe C++ is not really the best way to go for system calls like the ones you need to do here. Maybe shell scripting would be a better option.
Anyway, the easiest way is probably writing a third program that opens ApplicationA.exe, closes it and starts ApplicaionB.exe.
I believe in C++ you'd have to use system, which you find in <cstdlib>. Yes, it is a C feature, not a C++ one, and its use is not encouraged, to put it mildly.
I would recommend using the ShellExecute function. http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

How Do I Run an .exe From My Program and Obtain a Handle

How do I open a process and obtain a handle too it in C++. I know that there is system() and numerous methods to obtain a handle, but I'm sure there is a neater/alternative way to doing this. Or is system() the only way to open a .exe from inside your own?
A common way to do this is to use the Win32 API CreateProcess. The last parameter of this function is an out parameter to a structure (PROCESS_INFORMATION) containing the handle to the process (HANDLE hProcess).
Use ShellExecute

Using ShellExecuteEx and capturing standard in/out/err

I'm using ShellExecuteEx to execute a command in C. Is there a way to use ShellExecuteEx and capture standard in/out/err?
Note: I don't want to use CreateProcess.
I use to found the problem like you.
Suppose, You want to capture the output from STDOUT that it's generated by dir command and save the captured into out.txt.
Use text editor and type dir > out.txt and save it with mybat.bat (*.bat, don't *.txt)
In your c/c++ program, type WinExec("mybat.bat", SW_HIDE); and run your application.
Open the out.txt you will see the name of folders and files in current directory.
Also, you can run any executable files (*.exe) at the same way as follow.
xxx.exe > out.txt
I hope it can be helps you.
Sorry, my English really not good.
No. The only way to do this is to use CreatePipe and CreateProcess. See the MSDN article here
That's not possible. ShellExecute(Ex) basically executes the application in the context of the shell - so you are basically doing what explorer does.
Capturing STDIN and STDOUT is something the shell generally doesn't do, you you will have to go the CreateProcess route (which, after all, is what ShellExecute eventually calls if the file to execute is a program and the verb is 'open').
As mentioned by pilif and Bob, you need to use CreateProcess.
If you want code that wraps it all up for you, I do have a class for this exact issue at:
http://code.google.com/p/kgui/source/browse/trunk/kguithread.cpp.
The class (kGUICallThread) handles Linux, macOS and Windows versions. The code is licensed LGPL.
CreateProcess is what most people use.
You may also want to consider using _popen
http://msdn.microsoft.com/en-us/library/96ayss4b%28VS.80%29.aspx