Solved

Calling Scripts from C++

Posted on 2011-09-02
3
281 Views
Last Modified: 2013-11-27
How do I call a script (.bat, .PHP) asynchronously from C++.  Using system or CreateProcess causes my program to hang until the script is complete.  Thanks
0
Comment
Question by:andyshab
3 Comments
 
LVL 5

Expert Comment

by:-null-
ID: 36474191
Hi,

There are a number of ways you could achieve this, the most logical is to run the system call in a new thread.

Multithreaded programming is outside of the scope of this little box, but a quick google will bring up some really good examples

-null-
0
 

Author Comment

by:andyshab
ID: 36474215
A thread makes sense but seems like overkill.  I am currently called CreateProcess and not waiting for the process, just closing the hProcess and hThread handle right away.  This seems to work as long as I'm not leaking any resources.
0
 
LVL 7

Accepted Solution

by:
tampnic earned 250 total points
ID: 36478220
CreateProcess() creates a new process, thus a new thread. It shouldn't block, unless you are calling WaitForObject() in your code. CreateProcess() might hang around for a bit while Windows creates the new process so that a process handle can be returned by CreateProcess().

If you absolutely require the minimum wait time, you could call CreateThread() in your application and call CreateProcess() in the thread function, thus allowing your main application to continue with the minimum of hanging about. If your Windows environment is taking a long time to create a process, it might take nearly as long to set up a thread though. That needs evaluating in your target environment.

Cheers,
  Chris
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cannot debug web form sthrough Visual Studio 2013 2 70
Problem to DocumentFormat 8 91
Best book to learn C++ 4 78
Trouble with References... 5 53
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question