Solved

Calling Scripts from C++

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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