VectorM
Programmer
- May 4, 2008
- 2
Here's what I'm trying to do but need help achieving.
I want to service a web page request using a CGI program, which I'll call program A. I would like the CGI request to start program A, which will in turn communicate with program B and return some valves. Program B communicates with hardware and needs to run continuously. In short, the CGI request starts program A, A talks to B (already running), and A returns the web page to be served.
I'm running Apache 2.2 under Win 2000 professional. I have a basic web page that calls program A, which I have successfully written in Visual Basic 2005. It's a console application (as required) that starts and returns properly formatted web html pages. That part works.
I can also run program A DIRECTLY on the PC and it sends messages to program B. (Its html-formatted output is ignored, of course.) That part works.
However, when program A is called via the CGI call through Apache, it fails to be able to communicate with program B.
To be clear, the same exact program (A) run by me in windows will communicate with B successfully; however, when A is called by Apache through the CGI request, it fails to communicate.
Here are what I believe are the relevant details.
Program A finds and communicates with Program B using the core routine posted below. Through debugging, I have come to learn that the failure lies (or at least starts) in GetConsoleWindow() returning an empty handle when called through Apache. (When called directly by me, it returns a valid handle and the program works.)
I suspect that the problem is related to the "user identity" differences between me as a user and apache. It might be that when called by Apache, it does not have the permission to get a valid answer from GetConsoleWindow(). This is about as far I know how to take this.
Any help or suggestions? Perhaps I'm going about this all wrong.
___PROGRAM A___
'
' get a window handle, search for application "Message
' Recipient" and post a message
'
lWnd = GetConsoleWindow()
'
' the above returns a valid handle when run directly,
' but returns 0 when run through Apache/CGI call
Do
If lWnd = 0 Then
bFound = False
Exit Do
End If
lLen = GetWindowTextLength(lWnd)
sCaption = New String(Chr(0), lLen)
Call GetWindowText(lWnd, sCaption, lLen + 1)
If sCaption = "Message Recipient" Then
'send message to window
PostMessage(lWnd, CUSTOM_MSG, 0, 0)
bFound = True
Exit Do
End If
lWnd = GetNextWindow(lWnd, 2)
Loop
I want to service a web page request using a CGI program, which I'll call program A. I would like the CGI request to start program A, which will in turn communicate with program B and return some valves. Program B communicates with hardware and needs to run continuously. In short, the CGI request starts program A, A talks to B (already running), and A returns the web page to be served.
I'm running Apache 2.2 under Win 2000 professional. I have a basic web page that calls program A, which I have successfully written in Visual Basic 2005. It's a console application (as required) that starts and returns properly formatted web html pages. That part works.
I can also run program A DIRECTLY on the PC and it sends messages to program B. (Its html-formatted output is ignored, of course.) That part works.
However, when program A is called via the CGI call through Apache, it fails to be able to communicate with program B.
To be clear, the same exact program (A) run by me in windows will communicate with B successfully; however, when A is called by Apache through the CGI request, it fails to communicate.
Here are what I believe are the relevant details.
Program A finds and communicates with Program B using the core routine posted below. Through debugging, I have come to learn that the failure lies (or at least starts) in GetConsoleWindow() returning an empty handle when called through Apache. (When called directly by me, it returns a valid handle and the program works.)
I suspect that the problem is related to the "user identity" differences between me as a user and apache. It might be that when called by Apache, it does not have the permission to get a valid answer from GetConsoleWindow(). This is about as far I know how to take this.
Any help or suggestions? Perhaps I'm going about this all wrong.
___PROGRAM A___
'
' get a window handle, search for application "Message
' Recipient" and post a message
'
lWnd = GetConsoleWindow()
'
' the above returns a valid handle when run directly,
' but returns 0 when run through Apache/CGI call
Do
If lWnd = 0 Then
bFound = False
Exit Do
End If
lLen = GetWindowTextLength(lWnd)
sCaption = New String(Chr(0), lLen)
Call GetWindowText(lWnd, sCaption, lLen + 1)
If sCaption = "Message Recipient" Then
'send message to window
PostMessage(lWnd, CUSTOM_MSG, 0, 0)
bFound = True
Exit Do
End If
lWnd = GetNextWindow(lWnd, 2)
Loop