Hello everyone,
I am trying to figure out how to call GNUPLOT commands from a WINDOWS app. I am not coding in C++, I'm using WINDOWS APIs.
This is pretty straightforward problem if one is calling from a console app. Several developers (N. Devilla, for one) have done this. Their approach is to use _popen() (windows) or popen()(UNIX, LINUX). This approach doesnt work in a WINDOWS GUI app, however, only in a console app. It is also possible to use system()to do exactly the same thing.
Somehow there must be a way to invoke GNUPLOT using CreateProcess()after creating a pipe. But, I can't figure out how to do it. MSDN library has an example of redirecting using CreatePipe, but I can't understand how to apply it in this circumstance. Can someone suggest a solution?
Thanks,
Mark Allyn
1 4216
Here's an answer to my own question. I use anononymous pipe to a Gnuplot process. I WriteFile the plot commands on a redirected stdin handle. It works. It's ugly, but it does work. -
#include <windows.h>
-
#include <stdio.h>
-
#include <tchar.h>
-
-
int _tmain (int argc, LPTSTR argv [])
-
-
{
-
DWORD i;
-
HANDLE hReadPipe, hWritePipe;
-
-
SECURITY_ATTRIBUTES PipeSA = {sizeof (SECURITY_ATTRIBUTES), NULL, TRUE};
-
/* Init for inheritable handles. */
-
TCHAR outBuf[ ] = TEXT("a=2; plot sin(a*x)/x; pause mouse; plot exp(-a*x); pause mouse") ;
-
TCHAR inBuf[80];
-
DWORD dwWritten, dwRead ;
-
BOOL bSuccess = FALSE;
-
PROCESS_INFORMATION ProcInfo2;
-
STARTUPINFO StartInfoCh2;
-
-
-
/* Startup info for the Gnuplot process. */
-
-
GetStartupInfo (&StartInfoCh2);
-
-
/* Create an anonymous pipe with default size.
-
The handles are inheritable. */
-
-
bSuccess = CreatePipe (&hReadPipe, &hWritePipe, &PipeSA, 0);
-
if (bSuccess == TRUE) printf("pipe created\n");
-
-
WriteFile(hWritePipe, outBuf, sizeof(outBuf), &dwWritten, NULL) ;
-
printf("Wrote %d bytes to Gnuplot\n", dwWritten) ;
-
-
CloseHandle (hWritePipe);
-
-
/* Repeat (symmetrically) for the child process. */
-
-
StartInfoCh2.hStdInput = hReadPipe;
-
StartInfoCh2.hStdError = GetStdHandle (STD_ERROR_HANDLE);
-
StartInfoCh2.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
-
StartInfoCh2.dwFlags = STARTF_USESTDHANDLES;
-
bSuccess = FALSE ;
-
bSuccess = CreateProcess ("c:\\gnuplot\\bin\\pgnuplot.exe", NULL, NULL, NULL,
-
TRUE,0, NULL, NULL, &StartInfoCh2, &ProcInfo2);
-
if (bSuccess == TRUE)
-
printf("Created Gnuplot Process\n" ) ;
-
-
WaitForSingleObject (ProcInfo2.hProcess, INFINITE);
-
CloseHandle (ProcInfo2.hThread);
-
CloseHandle (hReadPipe);
-
-
/* Wait for Gnuplot process to complete.*/
-
-
CloseHandle (ProcInfo2.hProcess);
-
return 0;
-
}
-
Mark Allyn
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Harrison |
last post by:
What are the rule concerning calling member functions from an initialiser
list? Suppose I have
class C : public B
{
public:
C() : x(), y(f()), z() {}
private:
Y f();
X x;
|
by: Praveen Srinivasan |
last post by:
Hi all,
Are there any important issues that one should be aware of when calling C++
functions from C? In particular, I'm passing a function pointer to a C
routine in a library, and in that...
|
by: Joseph Suprenant |
last post by:
Hello all,
I have a C++ program, it does some calculations on things and then
prints out a file in the format in which GNUPLOT can use. So my question is
how would i call GNUPLOT from my C++...
|
by: reynoldscraigr |
last post by:
Hi All,
I am trying to call 2 functions from the 1 onMouseOver event on an
anchor tag, but I can't seem to get it to work. the following should
demonstrate
<a...
|
by: Ross A. Finlayson |
last post by:
Hi,
I hope you can help me understand the varargs facility.
Say I am programming in ISO C including stdarg.h and I declare a
function as so:
void log_printf(const char* logfilename, const...
|
by: Gerald Klix |
last post by:
I read the whol email thread carefully and could not find any sentence by
Guido, which states that he does not accept ctypes for the standard library.
He just declined to rewrite winreg. Did I miss...
|
by: Usenet User |
last post by:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile...
|
by: Meya-awe |
last post by:
Hi,
What does C# has to offer for calling system functions from within the
VS .NET C# project? I want to kickoff a script or a batch file from my
code.
thanks,
BRAMOIN
*** Sent via...
|
by: teju |
last post by:
hi,
i am trying 2 merge 2 projects into one project.One project is using c
language and the other one is using c++ code.
both are working very fine independently.But now i need to merge both...
|
by: teju |
last post by:
hi,
i have a code written in c now merged with c++ code i mean i am
calling c functions in c++ using extern "C" but now i want to use some
objects declared and defined in c++ to be available in...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |