M2 icon indicating copy to clipboard operation
M2 copied to clipboard

runProgram/findProgram wishlist

Open mahrud opened this issue 2 years ago • 5 comments

This is somehow the first time I've ever had to deal with these two methods, so here are some thoughts about what I expected before reading the documentation:

  1. normaliz = findProgram "normaliz" should work (e.g. if I'm just prototyping)
  2. runProgram("normaliz", "--version") should also work (e.g. if I'm just lazy)
  3. status runProgram(normaliz, "--version") should give the return code
  4. toString runProgram(normaliz, "--version") should give the string output
  5. normaliz << input should do the obvious thing, which is to run with that input
  6. MinimumVersion would be useless if I didn't know bash-fu. Why not take the minimum version and then a regex rule for getting the version from the output:
normaliz = findProgram("normaliz", "--version", "2.8", "Normaliz ([0-9.]+)")

Otherwise it would be simpler to just use get "!normaliz --version" (which is impossible to find in the documentation unless you already know about it!). Alternatively, if the version has to be extracted from a file, I would expect something like:

ver = select("NMZ_VERSION *([0-9.]+)", "$1", get "libnormaliz/version.h")
normaliz = findProgram("normaliz", "--version", ver)

That is, if there are only three arguments, the third argument is the stated version, but if there are four arguments, the 3rd one is the minimum version and the 4th is the regex for extracting it.

cc: @d-torrance

mahrud avatar Feb 04 '23 07:02 mahrud

Great suggestions!

d-torrance avatar Feb 04 '23 13:02 d-torrance

Just to clarify -- is this the behavior you were suggesting for Program << Thing?

i1 : M2 = findProgram "M2"

o1 = M2

o1 : Program

i2 : M2 << "2 + 2"

o2 = 0

o2 : ProgramRun

i3 : toString oo

o3 = 
     i1 : 2 + 2
          
     o1 = 4

d-torrance avatar Feb 04 '23 14:02 d-torrance

Exactly! It may be too much syntactic sugar, but easy to remember syntax gets used more :) We can think about this longer also, because perhaps something like this would also be nice:

runProgram(M2, "-q") << "2 + 2"

but that might require non-superficial changes.

mahrud avatar Feb 04 '23 18:02 mahrud

Updates:

  1. msolve = findProgram "msolve" doesn't work because running msolve alone prints help and returns code 1, which is not an uncommon choice. As long as the program is found and it is executable, I think this should return a Program object (i.e. the user chose not to provide a test command, so no need to test!)
  2. after running the above, msolve(args) should just work.
  3. moreover msolve_args << stdinput should also work.
  4. running findProgram("msolve", MinimumVersion => ("0.6.7", "msolve -V"), RaiseError => false) returns null if the version is too low. I think it should still return a Program object, but either with a warning or runProgram should then give an error.
  5. program#"version" should be program.Version perhaps.
  6. runProgram should also accept a list/sequence/hashtable/optiontable of args and insert spaces.

mahrud avatar Jul 25 '24 12:07 mahrud

  1. runProgram should have an option to display the stdout or at least stderr live, rather than keeping it for the end. It's important to know that status of some program (e.g. msolve) if it's going to take hours/days.

@d-torrance do you think you could implement this one soon? I actually think without this I would prefer to not use runProgram in Msolve.

mahrud avatar Aug 01 '24 22:08 mahrud