osx - Opening up Microsoft Word in my C++ program -


as title mentions, trying open microsoft word through program , running little bit of difficulty. having done research processes, decided go through route of working process id's , fork function handle opening file within program. area seem running difficulty exec family functions. seems variety of different uses these functions, having difficult time wrapping head around function should use , whether syntatically laying out arguments correctly.

my console prints following out screen when type "msword":

hello ---, application open?

msword

creating child process open microsoft word

parent process

opening microsoft word

#include <stdio.h> #include <iostream> #include <string>  // routine headers #include <sys/types.h> #include <unistd.h> using namespace std;  //function processes loading program, take result of searchapplication void loadapplication(string path) {     // if user typs microsoft word (msword abbreviation...)     if(path == "msword")     {         cout << "creating child process open microsoft word\n";         pid_t processid = fork();          if(processid == -1)         {         cout << "error creating process... exiting\n";         exit(1);         }         // child process         else if (processid == 0)         {             execle("/applications/microsoft office 2011", nullptr);         }         // parent process         else         {             cout << "parent process\n";         }     }  int main() {     cout << "hello ---, application open?\n";     string input;     cin >> input;     loadapplication(input);       return 0; } 

you don't have use fork/exec this. pass open command system():

#include <cstdlib>  int main() {    system("open /applications/app\\ store.app");    return 0; } 

note need escape spaces in application name (as shown above), , specify full name (not displayed name).

here's closely related question.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -