5

I want to look if cmake is installed in my system with Raku.

cmake --version at my command line gives:

cmake version 3.23.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).

One way I know (not sure if it is right or there are better ways) is:

my $cmake = shell('cmake --version').exitcode;
die "Aborting !, cmake installation is not present, 
          Install and try again," if $cmake != 0;

Is it a right way? Are there other better ways to handle it?

Its quite a generic question, it can help to test any other program.

Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
  • 2
    Assuming you want to check if `cmake` is *on the path*, that's the correct way to do it. "Installed in my system" is a fairly old-fashioned way of thinking about it; I can go grab a `cmake` instance off GitHub right now, put it in a folder in my Downloads, and add that to my path. Now I have a working `cmake` with no actual "install" step required (Notably, I never used `sudo` in any of those steps) – Silvio Mayolo Apr 16 '22 at 16:45
  • cf SO [Raku-native disk space usage](https://stackoverflow.com/questions/68620003/raku-native-disk-space-usage). – raiph Apr 16 '22 at 23:58

1 Answers1

1

Well, I'd probably use something like this, which does not depend on a specific command line argument

die unless shell "which @*ARGS[0]";

It will print the path if it finds it, die if it does not. But if your script works for you, there is more than one way to do it.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 1
    Yes its Unix specific. I was looking for cross-platform way of checking program, also applicable for Windows. – Suman Khanal Apr 20 '22 at 02:49
  • 1
    @SumanKhanal Please refer to the SO I linked in a comment on your Q. I intended that the general principles I wrote in the 4 options listed in **Part 1** of the accepted answer would directly apply to, and answer, related Qs like yours here, about doing some system work/check in a maximally portable way. The topic specific details differ, eg reporting storage space statistics vs checking for a program's presence, and .@uxer used the word "native" to mean portable, which threw me at first, but if you ignore those wrinkles it will hopefully make sense as the general outline of what is possible. – raiph May 04 '22 at 16:14