comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Test if a linux command is available with Spawn
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Test if a linux command is available with Spawn [message #86171] Wed, 16 October 2013 05:08 Go to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Hi IDLers,

I want to write a clipboard copy/paste function with IDL on Linux
systems. This is really straightforward with xclip. I just need to know
if the system I am working on has xclip installed. Based on
cgHasImageMagick, I could do:

IDL> Spawn, 'xclip -version', result, error_result

But xclip returns the version in the STDERR stream:

IDL> print, result

IDL> print, error_result
xclip version 0.12 Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL

This ok for me, but how to be sure that this is the case on all linux
systems?

Is there a "more general way" to do this?

Thanks a lot,

Fabien
Re: Test if a linux command is available with Spawn [message #86173 is a reply to message #86171] Wed, 16 October 2013 07:12 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
How about spawning "which", which should fairly standard on *nix:

spawn, 'which xclip', result
Re: Test if a linux command is available with Spawn [message #86195 is a reply to message #86171] Thu, 17 October 2013 05:56 Go to previous messageGo to next message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
On 16/10/13 14:08, Fabien wrote:
> Is there a "more general way" to do this?

I would do it this way:

IDL> spawn, 'ls awoiefsdkf 2>&1 ', asdf
IDL> print, asdf
ls: cannot access awoiefsdkf: No such file or directory

This forces the STDERR output into the STDOUT output. It works regardless of
if and what the command chooses to print where.

Please note that I only said the I would do it this way, not that it is an
elegent way of doing this.

Anyway, I thought this should be pretty general. Then I remembered that shells
other than bash exist. So, one would have to do both bash and csh versions. Or
force /bin/bash. Sorry.


chl
Re: Test if a linux command is available with Spawn [message #86196 is a reply to message #86195] Thu, 17 October 2013 06:00 Go to previous messageGo to next message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
On 17/10/13 14:56, Carsten Lechte wrote:
> Anyway, I thought this should be pretty general. Then I remembered that shells
> other than bash exist. So, one would have to do both bash and csh versions. Or
> force /bin/bash. Sorry.

In conclusion, it is probably best to concatenate your result and error_result
variables and work on that.

chl
Re: Test if a linux command is available with Spawn [message #86209 is a reply to message #86171] Thu, 17 October 2013 09:25 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Wednesday, October 16, 2013 6:08:51 AM UTC-6, Fabien wrote:
> Hi IDLers,
>
>
>
> I want to write a clipboard copy/paste function with IDL on Linux
>
> systems. This is really straightforward with xclip. I just need to know
>
> if the system I am working on has xclip installed. Based on
>
> cgHasImageMagick, I could do:
>
>
>
> IDL> Spawn, 'xclip -version', result, error_result
>
>
>
> But xclip returns the version in the STDERR stream:
>
>
>
> IDL> print, result
>
>
>
> IDL> print, error_result
>
> xclip version 0.12 Copyright (C) 2001-2008 Kim Saunders et al.
>
> Distributed under the terms of the GNU GPL
>
>
>
> This ok for me, but how to be sure that this is the case on all linux
>
> systems?
>
>
>
> Is there a "more general way" to do this?
>
>
>
> Thanks a lot,
>
>
>
> Fabien

Hi Fabien,
If you are just looking to copy/paste text (not images or files), and you can wait until IDL 8.3, we are adding routines to provide access to the system clipboard (text only) on all platforms.
Cheers,
Chris
VIS
Re: Test if a linux command is available with Spawn [message #86211 is a reply to message #86173] Thu, 17 October 2013 11:30 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 10/16/13 8:12 AM, Phillip Bitzer wrote:
> How about spawning "which", which should fairly standard on *nix:
>
> spawn, 'which xclip', result
>

I would check the EXIT_STATUS on "which xclip":

IDL> spawn, 'which xclip', stdout, stderr, exit_status=xclip_error
IDL> help, xclip_error
XCLIP_ERROR LONG = 1

Error code not 1 means there was a problem, in this case I don't have
xclip. If I have the program, it's like this:

IDL> spawn, 'which ls', stdout, stderr, exit_status=ls_error
IDL> help, ls_error
LS_ERROR LONG = 0

In this case, I don't need stdout/stderr output, but calling SPAWN with
them suppresses output to the output log.

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
Re: Test if a linux command is available with Spawn [message #86218 is a reply to message #86209] Fri, 18 October 2013 02:00 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Thanks everyone for the replies! Good to know that IDL8.3 will support
clipboard copy/paste. In the mean time I'll use Mike's solution with the
exit status. Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: NaN problem in integer arrays
Next Topic: Where does catalyst call the catEventDispatcher?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:52:12 PDT 2025

Total time taken to generate the page: 0.00469 seconds