Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iWill

macrumors member
Original poster
Nov 24, 2006
35
0
Hey guys now usually i hate it when people in this forum come and basically ask someone else to code for them...but i really need some information here that I'm struggling to find anywhere.
I would like to make a "quick launch" app in C++ where basically whenever you type in a keyword the app launches. First of all, is it possible to ask the program to "scan" the program files in order to see the list of programs and under what name they are. Second of all, what is the code that would let me execute the program that is typed in?

Thanks in advance, and again i do apologies for asking this type of favor.
 

ChrisA

macrumors G5
Jan 5, 2006
12,578
1,694
Redondo Beach, California
Hey guys now usually i hate it when people in this forum come and basically ask someone else to code for them...but i really need some information here that I'm struggling to find anywhere.
I would like to make a "quick launch" app in C++ where basically whenever you type in a keyword the app launches. First of all, is it possible to ask the program to "scan" the program files in order to see the list of programs and under what name they are. Second of all, what is the code that would let me execute the program that is typed in?

Thanks in advance, and again i do apologies for asking this type of favor.

You mean you want to write a program that does the same thing as the Bash shell where you only have to type in as many characters as are required to uniquely identify the command? If so, then it is easy. Bash uses the "readline" library and so can your program. In fact whenever i write software that accepts typed input from the user I always use readline this allows the user to do "command completion" and use the arrow keys to recall previous command, sear his history and so on, just like in Bash. Readline has a pretty much direct replacement for "getline" in stdio.h

But from you say, why not just use Bash itself?

Yes Bash does "scan" the list of program files. It scans and "remembers" all the executable files inside $PATH environment variable. It's not hard. Of course Bash is Open Source so you can read up and see how it works. Readline provide functions to "remember" the commands, not much you need to write.

What cde will execute the program? Again Bash is open source. But read the man (section 3) pages on "fork", and "exec". Typically the command interpetor calls "fork" and then the child process (created by "fork") calls "exec"


One of the best ways to write you own command interpeter is to get text from the user using readline and then send that to a lex/yacc parser and put some fork/exec calls into the yacc action rules.
 

Mydriasis

macrumors 6502
Mar 17, 2005
476
0
I know this is a stupid comment and dosen't help with the problem at hand, but I'd just use the keyboard short cut for spotlight, type in the first few letter, hit the down arrow once, then enter and voila.
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
I know this is a stupid comment and dosen't help with the problem at hand

Under normal circumstances, I'd say "then why post it?", but in this particular case you have stumbled on a truth of programming, namely that you should always ask "what problem am I trying to solve, has it been solved before, and can I use that solution?" Would have been better if you'd actually said that and then suggested your solution, but...
 

iWill

macrumors member
Original poster
Nov 24, 2006
35
0
I know this is a stupid comment and dosen't help with the problem at hand, but I'd just use the keyboard short cut for spotlight, type in the first few letter, hit the down arrow once, then enter and voila.
Yea I know but I've only made programs for 6months now so this is basically to test my capabilities.
And other thing, i know it's pretty dumb on my behalf to have posted this on a mac forum but i knew how you guys were responsive and helpful. This is a program I'm intending to make on windows (without the GUI though, just sticking to C++)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.