Solved

Calling Scripts from C++

Posted on 2011-09-02
3
279 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Import all database objects 12 45
TFS Branching 4 70
Application vs Workbook.applicaiton 3 33
Saving the SQL Login Credentials for Excel 2010 Microsoft Queries 1 96
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

930 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

9 Experts available now in Live!

Get 1:1 Help Now