Solved

Calling Scripts from C++

Posted on 2011-09-02
3
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…

733 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