0

I'm working on a program that can query running X apps, save all the commands of running apps and them reopen them latter.

I encounter an issue. wmctctl can query the pid of Onlyoffice, for example the pid is 123. Then run ps -ef -q 123, I see that the CMD is ./DesktopEditors which should be a invalid command, because ./one_command only can work in special folder include file one_command.

I can get a complete command by running ps -ef -q $(pgrep -P 123).

Is there a straight way to get the complete command of Onlyoffice just via wmctl and ps?

If there is a better way to get all commands of X apps, please let me know. Thanks.

1 Answers1

0

I suggest using ps -h -e -o pid,args command piped with a grep

This should provide full command path with it arguments and options.

For example find all running java programs with their arguments (might be extensive):

ps -eo pid,args | grep java

In your case I suggest a small awk script, that looks for the pid given as 3rd input field in current line:

wmctrl -l -p|awk '{system("ps -h --pid "$3" -o args")}'

Sample output

nautilus-desktop --force
/usr/libexec/gnome-terminal-server
/usr/libexec/gnome-terminal-server

update

Transforming current directory ./ to to full path. Assuming ./ represent the current working directory. Add the following pipe.

wmctrl -l -p|awk '{system("ps -h --pid "$3" -o args")}'|sed "s|^\./|$PWD/|"

Find the script or program DesktopEditors in your computer, using find / -name "DesktopEditors".

But I believe this is useless if you are trying to reverse engineer a web based application that requires some kind of a browser emulator.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
  • Your code maybe will simplify my code. Thanks. But if I run Onlyoffice. I only get `./DesktopEditors` if execute the command `wmctrl -l -p|awk '{system("ps -h --pid "$3" -o args")}'|grep Desktop`. – user8590543 May 26 '19 at 15:11
  • I want to get the complete command of Onlyoffice, not just `./DesktopEditors`. – user8590543 May 26 '19 at 15:18
  • than you replace ./ with $PWD. I added update to the answer. – Dudi Boy May 26 '19 at 15:51