|
|
Command line arguments
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status:
Offline
|
|
I was writing a program in MS Visual C++ 6.0 at school and I am trying to work on it on my Mac. The program requires the user to input command line arguments. This requires you to go to a command prompt and type
<program.exe> <arg1> <arg2>...
at the prompt to manually run your program (instead of clicking Build and Run in Xcode, or Execute in MSVC++). I had no trouble doing this on Windows, but I am wondering how to do this in OS X.
Any help is appreciated.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Use the Terminal? Sorry, I'm not seeing the difficulty.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
Ah; I see.
This has to do with something that Unix and Windows both call environment variables. Both actually have one called PATH, which is critical here. $PATH (or %PATH%, as Windows calls it), is used when you don't type the actual path to an executable: it tells the OS where to look for it. You can put more than one directory into PATH by separating them with colons in Unix (this:that) or semicolons in Windows (this;that). Typical values in Unix include "/usr/bin:/usr/sbin:/usr/X11R6/bin", while on Windows it's usually just "c windows\system32".
On Unix, you can check the value of $PATH with the command "echo $PATH". On Windows it's almost the same: "echo %PATH%".
Why am I mentioning this? Because there's actually one other thing about $PATH that you need to be aware of. Unix has three special path "aliases" (not the same as OSX aliases) which can be used as shortcuts. ".." stands for the folder containing the present one, "." stands for the present folder, and "~" stands for your home directory. Windows has the first two of these, but not the third.
Ahem. On Windows, "." is considered to be in your %PATH% by default. Actually, this is oversimplifying things, but it's accurate enough for our purposes. On Unix, "." is not in your $PATH by default, and although it's easy enough to add, it's considered poor security to add it. The reasons for this are a matter for another post.
So how do you run binaries from the current directory without having "." in your $PATH? You need to specify the path to the binary, but this is where those aliases I mentioned come in handy: "./ binary" is enough. Try that.
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status:
Offline
|
|
Thanks so much Millennium, that will save me some headaches. Works perfectly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|