Giving command line arguments to executable being run with ltrace/strace
Asked Answered
M

2

6

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. :)

Mummer answered 31/8, 2014 at 18:14 Comment(0)
V
9

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.

Vireo answered 31/8, 2014 at 18:18 Comment(2)
Thanks a lot! That did the trick. Can't believe I didn't try this myself :)Mummer
Cool. Also, for vexing command lines you might also want to look into -- (search for "unix double dash") although you don't need it in this case.Vireo
S
1

Using a double dash apparently also works:

ltrace [arguments to ltrace] -- command [arguments to command]

This 'trick' is shown in the syntax of ltrace's command line, although not explained in the manual. I gave it a shot (Linux Mint with bash).

Spaceband answered 6/5 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.