Thread: PgAgent - return code on batch step on Windows
Hi pgadmin team.<br /><br />I got a problem with PgAgent on Windows :<br />When I create a batch step, the status is alwaysset to succeed, even if the batch doesn't work.<br /><br />I found this in the source code (job.cpp) :<br /><br />#ifdef__WIN32__<br /> // The Windows way<br /> HANDLE h_script;<br /> DWORDdwRead; <br /> char chBuf[4098];<br /> <br /> h_script = win32_popen_r(filename.wc_str());<br/> [...]<br /> CloseHandle(h_script);<br /> <b>rc=1;</b><br/>#else<br /> // The *nix way.<br />[...]<br /><b> rc=pclose(fp_script);<br/> rc = (unsigned char)(rc >> 8); // The exit code is in the top 8 bits<br /> rc = (signed char)rc;<br /></b><br />the return code seems to be always true on windows platform, as the CloseHandle returncode is not used ?<br />Hope that'll help.<br /><br />Thank you.<br />
On Mon, Nov 22, 2010 at 12:06 PM, Julien Rouhaud <rjuju123@gmail.com> wrote: > Hi pgadmin team. > > I got a problem with PgAgent on Windows : > When I create a batch step, the status is always set to succeed, even if the > batch doesn't work. > > I found this in the source code (job.cpp) : > > #ifdef __WIN32__ > // The Windows way > HANDLE h_script; > DWORD dwRead; > char chBuf[4098]; > > h_script = win32_popen_r(filename.wc_str()); > [...] > CloseHandle(h_script); > rc=1; > #else > // The *nix way. > [...] > rc=pclose(fp_script); > rc = (unsigned char)(rc >> 8); // The exit code is in the top 8 bits > rc = (signed char)rc; > > the return code seems to be always true on windows platform, as the > CloseHandle return code is not used ? > Hope that'll help. CloseHandle is a generic function that returns a boolean indicating whether or not the handle was closed - it really doesn't tell us anything useful about what happened, unlike pclose(). Does something like this work? diff --git a/job.cpp b/job.cpp index 0611c93..08feb17 100644 --- a/job.cpp +++ b/job.cpp @@ -258,9 +258,8 @@ int Job::Execute() } } - + GetExitCodeProcess(h_script, (LPDWORD)&rc); CloseHandle(h_script); - rc=1; #else // The *nix way. -- Dave Page Blog: http://pgsnake.blogspot.com Twitter: @pgsnake EnterpriseDB UK: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Thanks for the fast answer.
I suppose this should work, but i can't build the windows program, i tried to use cmake but didn't manage to make it work :( (This is for my work and we have Delphi under windows, a proxy that prevent to use git and a lot of restrictions :/ )
I suppose this should work, but i can't build the windows program, i tried to use cmake but didn't manage to make it work :( (This is for my work and we have Delphi under windows, a proxy that prevent to use git and a lot of restrictions :/ )
On Mon, Nov 22, 2010 at 1:59 PM, Dave Page <dpage@pgadmin.org> wrote:
CloseHandle is a generic function that returns a boolean indicatingOn Mon, Nov 22, 2010 at 12:06 PM, Julien Rouhaud <rjuju123@gmail.com> wrote:
> Hi pgadmin team.
>
> I got a problem with PgAgent on Windows :
> When I create a batch step, the status is always set to succeed, even if the
> batch doesn't work.
>
> I found this in the source code (job.cpp) :
>
> #ifdef __WIN32__
> // The Windows way
> HANDLE h_script;
> DWORD dwRead;
> char chBuf[4098];
>
> h_script = win32_popen_r(filename.wc_str());
> [...]
> CloseHandle(h_script);
> rc=1;
> #else
> // The *nix way.
> [...]
> rc=pclose(fp_script);
> rc = (unsigned char)(rc >> 8); // The exit code is in the top 8 bits
> rc = (signed char)rc;
>
> the return code seems to be always true on windows platform, as the
> CloseHandle return code is not used ?
> Hope that'll help.
whether or not the handle was closed - it really doesn't tell us
anything useful about what happened, unlike pclose().
Does something like this work?
diff --git a/job.cpp b/job.cpp
index 0611c93..08feb17 100644
--- a/job.cpp
+++ b/job.cpp
@@ -258,9 +258,8 @@ int Job::Execute()
}
}
-
+ GetExitCodeProcess(h_script, (LPDWORD)&rc);--CloseHandle(h_script);
- rc=1;
#else
// The *nix way.
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Mon, Nov 22, 2010 at 1:18 PM, Julien Rouhaud <rjuju123@gmail.com> wrote: > Thanks for the fast answer. > I suppose this should work, but i can't build the windows program, i tried > to use cmake but didn't manage to make it work :( (This is for my work and > we have Delphi under windows, a proxy that prevent to use git and a lot of > restrictions :/ ) Urgh. Well, I've uploaded an executable to http://uploads.enterprisedb.com/download.php?file=29f93666171b286201bbe48f82609178 It's built using VC++ 2008, so you'll need to ensure you have the appropriate runtimes installed (you can download them from microsoft.com if needed). -- Dave Page Blog: http://pgsnake.blogspot.com Twitter: @pgsnake EnterpriseDB UK: http://www.enterprisedb.com The Enterprise PostgreSQL Company