[fpc-pascal] TProcess question
Bart
bartjunk64 at gmail.com
Sun Dec 14 15:56:47 CET 2008
> > 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).
>
>
> This is because it is not waited for.
Yeah, found that out myself after fiddling around just a little more.
> > Shouldn't trying to execute a non-executable file raise some kind
> > of exception (like it does in Windows)?
>
> You cannot do this reliably. Starting a new process in linux is a 2-step
> algorithm:
> 1 Fork a clone of the current process.
> 2 Execute the program that you want executed.
> If step 2 fails, then there is no way to return an error message to
> the parent process except a run-error code (127, I believe).
OK, I come from DOS, so my knowledge of "inside-linux" is alomost zero
at this point, so I did not know this.
This makes me wonder, howevr, how bash can tell me that I tried to
execute a non-executable file?
> > 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.)
>
>
> No, because this is bash-specific.
Well, learned 2 new things in 1 email ;-)
> >
> > 2.
> > Why does the GTK 1 app crash? This might be a GTK bug and not fpc related.
>
>
> I don't think it is fpc related.
That would suck then, since I guess GTK1 is "dead" (in the sence that
it is not maintained)?
> > ... 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).
> You can use the fpaccess() call with X_OK for this; But it is not a
> bullet-proof guarantee. You must know for sure which file exactly
> will be executed.
In my case I do know what file is executed (at leat I think I do know,
I supply the absolute path to the program), but checking for X_OK is
not a foolproof guarantee (see my remarks above).
> Well, you can try using fpaccess.
I borrowed this from somewhere in the code for the IDE (I believe):
function FileIsExecutable(const AFilename: string): boolean;
begin
Result:= BaseUnix.FpAccess(AFilename,BaseUnix.X_OK)=0;
end;
Thanks, for your input.
Bart
More information about the fpc-pascal
mailing list