7

How can I access the command line on Mac OS X without using argc, argv? On Linux, I would simply read /proc/self/cmdline or use GetCommandLine on Windows, but I can't find the equivalent for Mac OS X.

Anteru
  • 19,042
  • 12
  • 77
  • 121
  • 3
    You can use `sysctl()` to get at the raw argument space. See http://stackoverflow.com/questions/210397/get-other-process-argv-in-os-x-using-c/4633191#4633191 – Shawn Chin Aug 13 '12 at 16:40

1 Answers1

5

There are functions called _NSGetArgv and _NSGetArgc in crt_externs.h. However, wouldn't it be simpler to just store the argc/argv in a variable at the start of main and be portable to all three platforms?

NOTE: These functions are not directly documented, but they are mentioned in the documentation for NSApplicationMain in the Application Kit Functions Reference, and the related _NSGetEnviron is mentioned in the environ(7) manpage.

Random832
  • 37,415
  • 3
  • 44
  • 63