[fpc-pascal] TProcess question
bartjunk64 at gmail.com
Fri Dec 12 23:52:11 CET 2008
Just played with TProcess for the first time. (I come from Delphi 3)
I observed some oddities (?, or maybe I'm just dumb ...).
If you try to execute a process that is non-executable (like for
example a word doc), then on Windows an exception is raised and
GetLastOSError returns 193.
If you try this on (my) linux, no exception is raised and a
non-functional childprocess is forked (you can see it with ps ax).
If you do this in a GTK 1 app, however, then the app gets killed.
No errormessage, it just disappears.
On the console you can se some errormessage:
Xlib: unexpected async reply (sequence 0x4cf)
In GTK 2 app, there is no crash.
So 3 questions:
Shouldn't trying to execute a non-executable file raise some kind
of exception (like it does in Windows)?
If you try to execute a non-executable file from the console and query
for the exitcode that bash returns, it will return an exitcode of 126,
meaning: "Command invoked cannot execute" (Permission problem or
command is not an executable)
(This errorcode is not known to the syserrormessage function b.t.w.)
Why does the GTK 1 app crash? This might be a GTK bug and not fpc related.
As a way to work arond this (and at least preventing the crash): is
there a reliable way of cheking that a file can be executed in the
first place? I know I can check for the execute permission of the file
in question, but that is not enough (on my system any file copied from
my windows partition to linux will have the x permission set).
I tend to try to make my (silly) programs foolproof, so it would be
nice if either TProcess.Execute raises an error for this or I can
implement my workaraound, so I can present the user with an
appropriate errormessage, and not the app crash on him, or in the eyes
of the user do nothing at all, when the user expects it to execute
some other program...
More information about the fpc-pascal