tj / mon

mon(1) - Simple single-process process monitoring program written in C
1.08k stars 94 forks source link

Cannot pass arguments to programs #20

Closed joaojeronimo closed 11 years ago

joaojeronimo commented 11 years ago

Hi, I think I cannot pass arguments to programs.

For instance, I wrote server.js (which only starts a plain http server), and node server.js works as expected. If I add #! /usr/bin/env node to the file and chmod +x server.js, then ./server.js also works.

mon ./server.js also works as expected, but the problem is that I can't seem to get mon "node server.js" to work. I get this:

$ mon node test.js
mon : child 18797
mon : sh -c "node"
> 

Which is the nodejs prompt (node command with no argument).

tj commented 11 years ago

you have to quote variadic commands (mon "node test.js")

joaojeronimo commented 11 years ago

I don't get it... mon "node test.js" is exactly what I did, and got the output above.

I went digging through mon.c, and in line 485, const char *cmd = program.argv[0];, program.argv[0] is just node. program.argv[1] is test.js, and so on. I am quoting the commands...

tj commented 11 years ago

oh sorry I only read $ mon node test.js, ill take a look

tj commented 11 years ago

hmm on 1.2.0? ./mon "node -e 'console.log(5)'" for example works fine for me

joaojeronimo commented 11 years ago

Weird... I got unrecognized flag -e

joaojeronimo commented 11 years ago

Oh I'm so sorry, its completely my fault.

I was using mon with

mon () {                                                                   
  ~/.mon/mon $@                                                      
}

in my ~/.bashrc. I guess the quotes got lost with $@.

joaojeronimo commented 11 years ago

Quoting $@ like "$@" solves the problem.

mon () {
  ~/.mon/mon "$@"
}

Or I should have just used alias mon="~/.mon/mon"

tj commented 11 years ago

yup, or make install, or add ~/.mon to your PATH