1. system_exec() on Linux

According docs: "If it is not possible to run the program, system_exec() will
return -1."

While that happens on Windows, on Linux does not return -1 when trying to run a
program that does not exist.

Euphoria v. 2.5/3.l.1

Regards

new topic     » topic index » view message » categorize

2. Re: system_exec() on Linux

Julio C. Galaret Viera wrote:
> According docs: "If it is not possible to run the program, system_exec() will
> return -1."
> 
> While that happens on Windows, on Linux does not return -1 when trying to run
> a program that does not exist.
> 
> Euphoria v. 2.5/3.l.1

I tried the system_exec() example on Linux.
It didn't return a -1 error code, but did
return a non-zero code (32512) which indicates an error. 
Is that what you got?
Maybe I just need to change the documentation.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

3. Re: system_exec() on Linux

Robert Craig wrote:
> 
> Julio C. Galaret Viera wrote:
> > According docs: "If it is not possible to run the program, system_exec()
> > will
> > return -1."
> > 
> > While that happens on Windows, on Linux does not return -1 when trying to
> > run
> > a program that does not exist.
> > 
> > Euphoria v. 2.5/3.l.1
> 
> I tried the system_exec() example on Linux.
> It didn't return a -1 error code, but did
> return a non-zero code (32512) which indicates an error. 
> Is that what you got?
> Maybe I just need to change the documentation.
> 
> Regards,
>    Rob Craig
>    Rapid Deployment Software
>    <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>

Yes, I got that non-zero code but if successful also returns a non-zero code.
Can I rely on 32512 as being always returned when failing to run?

Regards

new topic     » goto parent     » topic index » view message » categorize

4. Re: system_exec() on Linux

Robert Craig wrote:
> 
> Julio C. Galaret Viera wrote:
> > According docs: "If it is not possible to run the program, system_exec()
> > will
> > return -1."
> > 
> > While that happens on Windows, on Linux does not return -1 when trying to
> > run
> > a program that does not exist.
> > 
> > Euphoria v. 2.5/3.l.1
> 
> I tried the system_exec() example on Linux.
> It didn't return a -1 error code, but did
> return a non-zero code (32512) which indicates an error. 
> Is that what you got?
> Maybe I just need to change the documentation.
> 
> Regards,
>    Rob Craig
>    Rapid Deployment Software
>    <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>

man system says:

The value returned is -1 on error if the fork fails; otherwise
return the status of the command.

The status returned depends on the type of job your executing.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

5. Re: system_exec() on Linux

I think that the Linux return code is in the rightmost byte of the return value
from the C system() call.

  sysret = system(pszCommand);
  result = ((sysret & 0xFF00) >> 8);

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

6. Re: system_exec() on Linux

Derek Parnell wrote:
> 
> I think that the Linux return code is in the rightmost byte of the return
> value
> from the C system() call.
> 
>   sysret = system(pszCommand);
>   result = ((sysret & 0xFF00) >> 8);
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell

Hmm. Interestingly enough, 32512 in hex is #7F00.

Wait, your expression would give the leftmost byte for result then shift it into
the lower eight bits. You lose the rightmost byte.

--
A complex system that works is invariably found to have evolved from a simple
system that works.
--John Gall's 15th law of Systemantics.

"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare

j.

new topic     » goto parent     » topic index » view message » categorize

7. Re: system_exec() on Linux

Looking at the man pages for system(3) and wait(2), though, Derek is right. you
should still get back -1 for an error, but your actual eight-bit exit status is
in the lower half of the word you get back.

Heh. Learn something new every day.

--
A complex system that works is invariably found to have evolved from a simple
system that works.
--John Gall's 15th law of Systemantics.

"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare

j.

new topic     » goto parent     » topic index » view message » categorize

8. Re: system_exec() on Linux

Julio C. Galaret Viera wrote:
> 
> Robert Craig wrote:
> > 
> > Julio C. Galaret Viera wrote:
> > > According docs: "If it is not possible to run the program, system_exec()
> > > will
> > > return -1."
> > > 
> > > While that happens on Windows, on Linux does not return -1 when trying to
> > > run
> > > a program that does not exist.
> > > 
> > > Euphoria v. 2.5/3.l.1
> > 
> > I tried the system_exec() example on Linux.
> > It didn't return a -1 error code, but did
> > return a non-zero code (32512) which indicates an error. 
> > Is that what you got?
> > Maybe I just need to change the documentation.
> 
> Yes, I got that non-zero code but if successful also returns a non-zero code.
> Can I rely on 32512 as being always returned when failing to run?

system_exec() is just returning to you what was returned to it,
I think by the Linux shell. I don't know if you can rely on 
that particular number being returned across different 
versions of Linux. It might be safer if you were to use 
some other method to check if the program actually exists
and ran successfully.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

9. Re: system_exec() on Linux

Robert Craig wrote:
> 
> system_exec() is just returning to you what was returned to it,
> I think by the Linux shell. I don't know if you can rely on 
> that particular number being returned across different 
> versions of Linux. It might be safer if you were to use 
> some other method to check if the program actually exists
> and ran successfully.
> 
> Regards,
>    Rob Craig
>    Rapid Deployment Software
>    <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>


Thanks.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu