Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Command line arguments

Command line arguments
Thread Tools
nbn22385
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status: Offline
Reply With Quote
Oct 5, 2006, 01:04 AM
 
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.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 5, 2006, 01:20 AM
 
Use the Terminal? Sorry, I'm not seeing the difficulty.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
nbn22385  (op)
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status: Offline
Reply With Quote
Oct 5, 2006, 02:19 AM
 
I'm not sure what to type. Here is what I tried with a test program.

http://img227.imageshack.us/img227/4458/picture1ft9.png
     
Millennium
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Oct 5, 2006, 06:39 AM
 
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 "cwindows\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!
     
nbn22385  (op)
Dedicated MacNNer
Join Date: Nov 2004
Location: Orlando, FL
Status: Offline
Reply With Quote
Oct 6, 2006, 08:50 PM
 
Thanks so much Millennium, that will save me some headaches. Works perfectly.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:35 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,