Closed Bajger closed 9 months ago
Will add unit tests in additional commit
@demarey Hi Christophe! Finally had chance to provide needed changes. Please take a look!
Found the issue in parsing line with process information. I didn't test it with pharo processes that run with --headless parameter (or other vm or image params). Therefore parsing is shifted.
I need to resolve OS args passing (on MacOS), here is the situation, when no Pharo process (except launcher) is running:
dbajger@Davids-MacBook-Pro P11-launcher-dev % "/Users/dbajger/Documents/Pharo/vms/110-x64/Pharo.app/Contents/MacOS/Pharo" --headless "/Users/dbajger/Documents/Pharo/images/P11-launcher-dev-proc-list/P11-launcher-dev-proc-list.image" clap launcher image processList
PhLProcessCommandError: OS process command: '/bin/zsh -c pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 49997' exited with: normal termination with status 1.
Stderr contents: "".
but if I start some pharo image, it works:
dbajger@Davids-MacBook-Pro P11-launcher-dev % "/Users/dbajger/Documents/Pharo/vms/110-x64/Pharo.app/Contents/MacOS/Pharo" --headless "/Users/dbajger/Documents/Pharo/images/P11-launcher-dev-proc-list/P11-launcher-dev-proc-list.image" clap launcher image processList
# PID Image name VM path Image path Date/Time started
-- ----- ---------- -------------------------------------------------- -------------------------------------------------- --------------------
1 50017 P11-OTE /Users/dbajger/Documen ... pp/Contents/MacOS/Pharo /Users/dbajger/Documen ... s/P11-OTE/P11-OTE.image 2024-01-31 08:49:07
Problem is in args after /bin/zsh -c
, if no process is running then it looks like this:
/bin/zsh -c pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 49997
usage: pgrep [-Lfilnoqvx] [-d delim] [-F pidfile] [-G gid]
[-P ppid] [-U uid] [-g pgrp] [-t tty] [-u euid]
pattern ...
but if I put it in double qoutes (on terminal) it works:
/bin/zsh -c "pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 49997"
dbajger@Davids-MacBook-Pro P11-launcher-dev %
So I tried to to put each arg to be surrounded by double quoutes:
osShellArgArray
^ Array with: self processListCmdArgs surroundedByDoubleQuotes
But it resulted in different error:
dbajger@Davids-MacBook-Pro P11-launcher-dev % "/Users/dbajger/Documents/Pharo/vms/110-x64/Pharo.app/Contents/MacOS/Pharo" --headless "/Users/dbajger/Documents/Pharo/images/P11-launcher-dev-proc-list/P11-launcher-dev-proc-list.image" clap launcher image processList
PhLProcessCommandError: OS process command: '/bin/zsh -c "pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 50592"' exited with: normal termination with status 127.
Stderr contents: "zsh:1: command not found: pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 50592
".
@demarey Do you have idea, how exactly should be args qouted to OSProcess command? I pass pgrep with all stuff after as one argument (as seen in osShellArgArray
method).
Hi David
From the system point of view, the command you are running is /bin/zsh
and it has 2 arguments: -c
and a string with all the other parts of the command. Inside the string, you have another command that will be run by zsh
. It also has to be a valid command. The biggest issue is when you have spaces in arguments. To avoid problems, you can add single or double quotes around all arguments. To summarize, what should be done is:
run zsh command with a string protected with single (or double) quotes protect arguments in the command string that will be executed bu the shell with double quotes (could be single but not the same used for the zsh command)
This is what I've thought of. I've surrounded pgrep and all its args as one argument surrounded by double qoutes. So why I have and error like this?
launcher image processList
PhLProcessCommandError: OS process command: '/bin/zsh -c "pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 50592"' exited with: normal termination with status 127.
Stderr contents: "zsh:1: command not found: pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 50592
".
If I put exactly the same string in the terminal: /bin/zsh -c "pgrep -ai -f 'pharo.*\.image' | xargs ps -o pid,args= -p | grep -v -e 'PID' | grep -v '.bash'| grep -v 'export LD_LIBRARY_PATH' | grep -v 50592"
It works.
What looks weird that command not found
error output prints command with ending quote, but not with starting quote. Maybe some newline character could be there?
Maybe it has something to do with parameter expansion. In PL, the launch command does exactly what I explained below. Here is an example;
bash -c 'cd "/Users/me/Documents/Pharo/images/Pharo 11.0" && "/Users/me/Documents/Pharo/vms/110-x64/Pharo.app/Contents/MacOS/Pharo" "/Users/me/Documents/Pharo/images/Pharo 11.0/Pharo 11.0.image"'
@demarey Please take a look. Process list identification should be robust enough now, I hope I found all cornercases for pgrep. Should be working both on Linux and MacOS (tested).
Note: There was a funny problem which I could not identify, since pgrep returns exitCode 1 in case of no process match. This resulted in exception in OS Shell command execution in Pharo - since exitSuccess is tested there. Lessons learned (read man pages) :-)
I did a local merge with dev branch and running tests. I see a problem with date convertion:
OS process command: '/bin/zsh -c ps -o lstart= -p "1974" | xargs -I{} date -jf "%a %b %e %T %Y" "{}" '+%Y-%m-%d %H:%M:%S'' exited with: normal termination with status 1.
Stderr contents: "Failed conversion of ``Lun 29 jan 12:34:40 2024'' using format ``%a %b %e %T %Y''
date: illegal time format
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
[-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
[[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
".
Lun 29 jan 12:34:40 2024
This is date in French localization? I will test with it.
Lun 29 jan 12:34:40 2024
This is date in French localization? I will test with it.
Yes. And maybe there could be other issues with otherlocalizations. Maybe there is a way to use an ISO format ?
@demarey: Please try now.
@demarey: Please try now.
Not yet
OS process command: '/bin/zsh -c LANG=C ps -o lstart= -p "1974" | xargs -I{} date -jf "%a %b %e %T %Y" "{}" '+%Y-%m-%d %H:%M:%S'' exited with: normal termination with status 1.
Stderr contents: "Failed conversion of ``Mon Jan 29 12:34:40 2024'' using format ``%a %b %e %T %Y''
date: illegal time format
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
[-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
[[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
".
This is strange, if I evaluate on my MacOS:
dbajger@Davids-MacBook-Pro P11-launcher-dev % LANG=C ps -o lstart= -p 50442 | xargs -I{} date -jf "%a %b %e %T %Y" "{}" '+%Y-%m-%d %H:%M:%S'
2024-01-31 09:07:55
So on my computer works. I don't know. Date formatting to ISO is really clumsy.
after investigation the command that works on my mac is:
date -j -u -f "%a %d %b %H:%M:%S %Y" '+%Y-%m-%d %H:%M:%S' "Lun 29 jan 12:26:05 2024"
@demarey Tested on my Mac with adopted time attributes (https://github.com/pharo-project/pharo-launcher/pull/617/commits/571fa76afdd7c6bdf14c38a6b69494c1505be832) . Please let me know!
@Bajger Did you see my PR on this topic on your repository?
@Bajger Did you see my PR on this topic on your repository?
Hi @demarey ! Sorry I didn't recognize that. To resolve conflicts, I need to checkout my branch or https://github.com/pharo-project/pharo-launcher/tree/enh/PR616 ?
GitHubLets you manage your pharo images and download new ones - GitHub - pharo-project/pharo-launcher at enh/PR616
Hi @demarey ! Sorry I didn't recognize that. To resolve conflicts, I need to checkout my branch or https://github.com/pharo-project/pharo-launcher/tree/enh/PR616 ?
I just diid the merge. The PR is up to date
GitHubLets you manage your pharo images and download new ones - GitHub - pharo-project/pharo-launcher at enh/PR616
fixes #616