Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5928783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:19:59+00:00 2026-05-22T14:19:59+00:00

Is it possible to open a program using another program? For example: I want

  • 0

Is it possible to open a program using another program? For example:
I want to make a command line application in C that will prompt the user to type in the name of a program (lets say Microsoft Word.app), and that program will launch. Would I do something like this:

#include <stdio.h>
#include <time.h>
int main (int argc, const char * argv[]) {
    char programName[1000];
    printf("Type in the name of the program you would like to open: ");
    scanf("%s", programName);
    popen(programName);
}

However, popen() asks me for another char. How would I go about using popen() to open the program?

EDIT: The following code works!

#include <stdio.h>
#include <time.h>

int main (int argc, const char * argv[]) {
    char programName[1000];
    char app[100] = ".app";
    char openApp[100] = "open /Applications/";
    printf("Type in the name of the program you would like to open: ");
    scanf("%s", programName);
    strcat(openApp, programName);
    strcat(openApp, app);
    system(openApp);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:20:00+00:00Added an answer on May 22, 2026 at 2:20 pm

    popen lets you launch a program and get a file descriptor to its input or output, much like fopen works for files. For instance, if you wanted to read the output of your program, you’d use popen("program", "r"). On the other hand, if you want to write to its input, you would use popen("program", "w"). Mac OS X also allows for r+, which lets you read the output and write to the input but this capability isn’t standard and shouldn’t be relied on for cross-platform code.

    If you just want to launch a program, you might as well use the system function, which does that and waits until the program exits, at which point it returns the status code. system actually invokes the shell to work, so arguments will undergo expansion (environment variables, ~, etc).

    EDIT Following your comment that system("Microsoft Word.app") doesn’t work as you’d expect: there are several reasons for this, actually. Starting with the message you get: this is because what you wrote is equivalent to opening a terminal window and typing Microsoft Word.app. In other words, it tries to find a program called “Microsoft”, then pass it the argument “Word.app”. You would need to either quote the program name or escape spaces to have the shell understand it’s a whole program name and not a program name then an argument: system("Microsoft\ Word.app")

    Now, this should complain saying that the shell can’t find the program “Microsoft Word.app”, which is already a step forward.

    This is because on Mac OS, app files aren’t executable files: they’re folders that the Finder displays as a single file. You can verify that by ctrl+clicking (or right-clicking) an app and selecting “Show package contents” (this will open the app folder). The actual executable for Microsoft Word.app must be somewhere along the path of Microsoft Word.app/Contents/MacOS/Microsoft Word.

    As you can see, this is getting kind of complex. Luckily enough, Apple provides the open executable, which can use a bunch of OS services to figure out those details. It allows to launch applications in the following fashion:

    open -a Microsoft\ Word
    

    This should launch Word. (Notice how you still need to escape the spaces.) In pure C code, that would get you something like this:

    system("open -a Microsoft\\ Word");
    

    If you choose to use Objective-C and Cocoa, however, there is a very simple way to open applications:

    NSString* appName = @"Microsoft Word"; // no escape!
    [[NSWorkspace sharedWorkspace] launchApplication:appName];
    

    NSString objects can be created from C string easily enough:

    NSString* appName = [[NSString alloc] initWithCString:programName encoding:NSUTF8StringEncoding];
    [[NSWorkspace sharedWorkspace] launchApplication:appName];
    [appName release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to open the command prompt (and I guess any other terminal
I want to implement in my program functionality, which will make it able to
im using an open source program called Festival that generates text to speech, and
I am working on a C program that will run in user space on
Is it possible to open an iPhone application or an Xcode project from the
Is is possible to open a text file and read the contents while another
I know its possible to open an app from mobile safari using custom URL
Is it possible to open an mp3 file in Python (possible using Popen )
I want to create a directory by using program in android sdk. Is it
I'm using a program that stores its log files at C:\Windows\System32\config\systemprofile\AppData\Roaming\ProgramName\*.log , but for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.