4

The title says it all friends!

How do I give command line arguments to an executable whose execution I want to monitor using ltrace/strace ?

For example, if the executable is 'a.out' and I want to store ltrace's output in a file 'out.txt' and 'arg1' is a command line argument that I want to pass to the execuable, then the command I tried is this "ltrace ./a.out -o arg1 out.txt"

The problem is my program is designed to work only for a single command line argument, so when I run the above command, my program interprets this as multiple command line arguments and stops execution after printing a "Usage" message (it is actually designed to do this but here I want to monitor the library calls it is making).

Can someone please help me out ? Thanks in advance. :)

Iceflame007
  • 147
  • 2
  • 11

1 Answers1

8

Try passing -o before the command to execute:

ltrace -o out.txt ./a.out arg1

This way ltrace will get -o out.txt and then will exec a.out, passing to it the rest of the command line.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • Thanks a lot! That did the trick. Can't believe I didn't try this myself :) – Iceflame007 Aug 31 '14 at 18:48
  • Cool. Also, for vexing command lines you might also want to look into `--` (search for ["unix double dash"](http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html)) although you don't need it in this case. – cnicutar Aug 31 '14 at 18:49