unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* execlp
@ 2011-11-22 16:06 Paul Emsley
  2011-11-23  5:47 ` execlp Nala Ginrut
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Emsley @ 2011-11-22 16:06 UTC (permalink / raw)
  To: guile-user


Hi,

I am trying to see if there is a way to determine if a program is in the 
path (i.e. a bit like "which"), returning a #t or #f answer.  I was 
looking execl and execlp.

The documentation for execl says:

 > Executes the file named by path as a new process image

what is path ?  I'm guessing that that should be "filename".

While playing around, I notice that

(execlp "ls")

produces a core dump.

My question is then, *is* there a way to determine if a string is 
executable? (And if so, how? :-)

Thanks,

Paul.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-22 16:06 execlp Paul Emsley
@ 2011-11-23  5:47 ` Nala Ginrut
  2011-11-23  5:57   ` execlp Nala Ginrut
  2011-11-23 12:16   ` execlp Paul Emsley
  0 siblings, 2 replies; 9+ messages in thread
From: Nala Ginrut @ 2011-11-23  5:47 UTC (permalink / raw)
  To: Paul Emsley, guile-user

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

I think there's a bug.
(execlp "ls" "") will access.
Since the second parameter is optional, scm_execlp doesn't handle exec_argv
unbounded situation.


On Wed, Nov 23, 2011 at 12:06 AM, Paul Emsley <paul.emsley@bioch.ox.ac.uk>wrote:

>
> Hi,
>
> I am trying to see if there is a way to determine if a program is in the
> path (i.e. a bit like "which"), returning a #t or #f answer.  I was looking
> execl and execlp.
>
> The documentation for execl says:
>
> > Executes the file named by path as a new process image
>
> what is path ?  I'm guessing that that should be "filename".
>
> While playing around, I notice that
>
> (execlp "ls")
>
> produces a core dump.
>
> My question is then, *is* there a way to determine if a string is
> executable? (And if so, how? :-)
>
> Thanks,
>
> Paul.
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 1253 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23  5:47 ` execlp Nala Ginrut
@ 2011-11-23  5:57   ` Nala Ginrut
  2011-11-23 12:16   ` execlp Paul Emsley
  1 sibling, 0 replies; 9+ messages in thread
From: Nala Ginrut @ 2011-11-23  5:57 UTC (permalink / raw)
  To: Paul Emsley, guile-user

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

Well, I noticed your second question. ;-)
The common method to determine a executable file is stat:perms, you may
check it out in the manual for details.

On Wed, Nov 23, 2011 at 1:47 PM, Nala Ginrut <nalaginrut@gmail.com> wrote:

> I think there's a bug.
> (execlp "ls" "") will access.
> Since the second parameter is optional, scm_execlp doesn't handle
> exec_argv unbounded situation.
>
>
> On Wed, Nov 23, 2011 at 12:06 AM, Paul Emsley <paul.emsley@bioch.ox.ac.uk>wrote:
>
>>
>> Hi,
>>
>> I am trying to see if there is a way to determine if a program is in the
>> path (i.e. a bit like "which"), returning a #t or #f answer.  I was looking
>> execl and execlp.
>>
>> The documentation for execl says:
>>
>> > Executes the file named by path as a new process image
>>
>> what is path ?  I'm guessing that that should be "filename".
>>
>> While playing around, I notice that
>>
>> (execlp "ls")
>>
>> produces a core dump.
>>
>> My question is then, *is* there a way to determine if a string is
>> executable? (And if so, how? :-)
>>
>> Thanks,
>>
>> Paul.
>>
>>
>>
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 1778 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23  5:47 ` execlp Nala Ginrut
  2011-11-23  5:57   ` execlp Nala Ginrut
@ 2011-11-23 12:16   ` Paul Emsley
  2011-11-23 12:22     ` execlp Nala Ginrut
                       ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: Paul Emsley @ 2011-11-23 12:16 UTC (permalink / raw)
  To: guile-user

Hi Nala Ginrut,

Thanks for your reply.

I suspect I expressed myself poorly. (execlp "ls" "") replaces guile 
with "ls", which lists my files and returns me to the shell.

What is some-function, where some-function works like this:

(some-function "ls")
-> "/bin/ls"  (I'd settle for #t")
(some-function "asdfasdf")
-> #f

I thought that execl or its friends would be the way to answer that 
question...

Thanks,

Paul.


On 23/11/11 05:47, Nala Ginrut wrote:
> I think there's a bug.
> (execlp "ls" "") will access.
> Since the second parameter is optional, scm_execlp doesn't handle 
> exec_argv unbounded situation.
>
>
> On Wed, Nov 23, 2011 at 12:06 AM, Paul Emsley 
> <paul.emsley@bioch.ox.ac.uk <mailto:paul.emsley@bioch.ox.ac.uk>> wrote:
>
>
>     Hi,
>
>     I am trying to see if there is a way to determine if a program is
>     in the path (i.e. a bit like "which"), returning a #t or #f
>     answer.  I was looking execl and execlp.
>
>     The documentation for execl says:
>
>     > Executes the file named by path as a new process image
>
>     what is path ?  I'm guessing that that should be "filename".
>
>     While playing around, I notice that
>
>     (execlp "ls")
>
>     produces a core dump.
>
>     My question is then, *is* there a way to determine if a string is
>     executable? (And if so, how? :-)
>
>     Thanks,
>
>     Paul.
>
>
>
>
>




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23 12:16   ` execlp Paul Emsley
@ 2011-11-23 12:22     ` Nala Ginrut
  2011-11-23 12:28     ` execlp Nala Ginrut
  2011-11-23 19:18     ` execlp Thien-Thi Nguyen
  2 siblings, 0 replies; 9+ messages in thread
From: Nala Ginrut @ 2011-11-23 12:22 UTC (permalink / raw)
  To: Paul Emsley; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1672 bytes --]

Well, I'm glad to help. ;-)
And I think any "Segment Fault" must be a bug. So I sent a letter for this
in guile-dev.

On Wed, Nov 23, 2011 at 8:16 PM, Paul Emsley <paul.emsley@bioch.ox.ac.uk>wrote:

> Hi Nala Ginrut,
>
> Thanks for your reply.
>
> I suspect I expressed myself poorly. (execlp "ls" "") replaces guile with
> "ls", which lists my files and returns me to the shell.
>
> What is some-function, where some-function works like this:
>
> (some-function "ls")
> -> "/bin/ls"  (I'd settle for #t")
> (some-function "asdfasdf")
> -> #f
>
> I thought that execl or its friends would be the way to answer that
> question...
>
> Thanks,
>
> Paul.
>
>
>
> On 23/11/11 05:47, Nala Ginrut wrote:
>
>> I think there's a bug.
>> (execlp "ls" "") will access.
>> Since the second parameter is optional, scm_execlp doesn't handle
>> exec_argv unbounded situation.
>>
>>
>> On Wed, Nov 23, 2011 at 12:06 AM, Paul Emsley <paul.emsley@bioch.ox.ac.uk<mailto:
>> paul.emsley@bioch.ox.**ac.uk <paul.emsley@bioch.ox.ac.uk>>> wrote:
>>
>>
>>    Hi,
>>
>>    I am trying to see if there is a way to determine if a program is
>>    in the path (i.e. a bit like "which"), returning a #t or #f
>>    answer.  I was looking execl and execlp.
>>
>>    The documentation for execl says:
>>
>>    > Executes the file named by path as a new process image
>>
>>    what is path ?  I'm guessing that that should be "filename".
>>
>>    While playing around, I notice that
>>
>>    (execlp "ls")
>>
>>    produces a core dump.
>>
>>    My question is then, *is* there a way to determine if a string is
>>    executable? (And if so, how? :-)
>>
>>    Thanks,
>>
>>    Paul.
>>
>>
>>
>>
>>
>>
>
>

[-- Attachment #2: Type: text/html, Size: 2581 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23 12:16   ` execlp Paul Emsley
  2011-11-23 12:22     ` execlp Nala Ginrut
@ 2011-11-23 12:28     ` Nala Ginrut
  2011-11-23 14:03       ` execlp rixed
  2011-11-23 19:18     ` execlp Thien-Thi Nguyen
  2 siblings, 1 reply; 9+ messages in thread
From: Nala Ginrut @ 2011-11-23 12:28 UTC (permalink / raw)
  To: Paul Emsley; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 807 bytes --]

On Wed, Nov 23, 2011 at 8:16 PM, Paul Emsley <paul.emsley@bioch.ox.ac.uk>wrote:

> Hi Nala Ginrut,
>
> Thanks for your reply.
>
> I suspect I expressed myself poorly. (execlp "ls" "") replaces guile with
> "ls", which lists my files and returns me to the shell.
>
> What is some-function, where some-function works like this:
>
> (some-function "ls")
> -> "/bin/ls"  (I'd settle for #t")
> (some-function "asdfasdf")
> -> #f
>
> I thought that execl or its friends would be the way to answer that
> question...
>
>
I think there's no such a given function in Guile to do this.
But you can make it in a easy way in Guile:
(catch 'system-error
    (lambda () (execlp "asdfasdf"))
      (lambda (k . e)
         (format #t "oh no~%~")))

PS: Maybe you need #f instead of "format" according to your letter. ;-)

[-- Attachment #2: Type: text/html, Size: 1336 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23 12:28     ` execlp Nala Ginrut
@ 2011-11-23 14:03       ` rixed
  2011-11-23 14:38         ` execlp Nala Ginrut
  0 siblings, 1 reply; 9+ messages in thread
From: rixed @ 2011-11-23 14:03 UTC (permalink / raw)
  To: guile-user

-[ Wed, Nov 23, 2011 at 08:28:56PM +0800, Nala Ginrut ]----
> I think there's no such a given function in Guile to do this.
> But you can make it in a easy way in Guile:
> (catch 'system-error
>     (lambda () (execlp "asdfasdf"))
>       (lambda (k . e)
>          (format #t "oh no~%~")))
> 
> PS: Maybe you need #f instead of "format" according to your letter. ;-)

It's my understanding that the OP does not want to actually run the
program but merely knows either the file is in the PATH or not.

I guess some-function would be something like :

(use-modules (srfi srfi-1)) ; for any
(define (in-path? f)
	(let ((path          (string-split (getenv "PATH") #\:))
		  (make-absolute (lambda (path) (string-append path "/" f))))
		(any file-exists? (map make-absolute path))))





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23 14:03       ` execlp rixed
@ 2011-11-23 14:38         ` Nala Ginrut
  0 siblings, 0 replies; 9+ messages in thread
From: Nala Ginrut @ 2011-11-23 14:38 UTC (permalink / raw)
  To: rixed, guile-user, Paul Emsley

[-- Attachment #1: Type: text/plain, Size: 1395 bytes --]

On Wed, Nov 23, 2011 at 10:03 PM, <rixed@happyleptic.org> wrote:

> -[ Wed, Nov 23, 2011 at 08:28:56PM +0800, Nala Ginrut ]----
> > I think there's no such a given function in Guile to do this.
> > But you can make it in a easy way in Guile:
> > (catch 'system-error
> >     (lambda () (execlp "asdfasdf"))
> >       (lambda (k . e)
> >          (format #t "oh no~%~")))
> >
> > PS: Maybe you need #f instead of "format" according to your letter. ;-)
>
> It's my understanding that the OP does not want to actually run the
> program but merely knows either the file is in the PATH or not.
>
> I guess some-function would be something like :
>
> (use-modules (srfi srfi-1)) ; for any
> (define (in-path? f)
>        (let ((path          (string-split (getenv "PATH") #\:))
>                  (make-absolute (lambda (path) (string-append path "/"
> f))))
>                (any file-exists? (map make-absolute path))))
>
>
>
Well, I realized that Paul want this some-function to detect whether file
can be executed.
[quote] My question is then, *is* there a way to determine if a string is
executable? (And if so, how? :-) .[/quote]
I confess that I didn't quite understand this question.
So I guess there're two alternatives:
1. He needs some-function to detect each file in a path an return the
result or #f;
2. He needs some-function to handle the error if a certain string can not
be executed.

[-- Attachment #2: Type: text/html, Size: 2632 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execlp
  2011-11-23 12:16   ` execlp Paul Emsley
  2011-11-23 12:22     ` execlp Nala Ginrut
  2011-11-23 12:28     ` execlp Nala Ginrut
@ 2011-11-23 19:18     ` Thien-Thi Nguyen
  2 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2011-11-23 19:18 UTC (permalink / raw)
  To: Paul Emsley; +Cc: guile-user

() Paul Emsley <paul.emsley@bioch.ox.ac.uk>
() Wed, 23 Nov 2011 12:16:47 +0000

   What is some-function, where some-function works like this:

   (some-function "ls")
   -> "/bin/ls"  (I'd settle for #t")
   (some-function "asdfasdf")
   -> #f

You can try something like:

(use-modules (srfi srfi-13) (srfi srfi-14))

(define (some-function program)
  (and=> (search-path (string-tokenize (getenv "PATH")
                                       (char-set-complement
                                        (char-set #\:)))
                      program)
         (lambda (filename)
           (and (access? filename X_OK)
                filename))))



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-11-23 19:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-22 16:06 execlp Paul Emsley
2011-11-23  5:47 ` execlp Nala Ginrut
2011-11-23  5:57   ` execlp Nala Ginrut
2011-11-23 12:16   ` execlp Paul Emsley
2011-11-23 12:22     ` execlp Nala Ginrut
2011-11-23 12:28     ` execlp Nala Ginrut
2011-11-23 14:03       ` execlp rixed
2011-11-23 14:38         ` execlp Nala Ginrut
2011-11-23 19:18     ` execlp Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).