Solved

Calling Scripts from C++

Posted on 2011-09-02
3
276 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-
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now