0

I'm using fork() to create new process.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <ncurses.h>
#include <iostream>
#include <time.h>

int main (void) 
{
    switch (fork())
    {
        case -1: exit(0);
        case 0: {
            execl("Terminal.app", "shell", "-e", "time ls; shell", (char*)0);
            break;
        }
        default: {
            std::cout << "OK" << std::endl;
            initscr();
            time_t secs = time(NULL);
            tm* timeInfo = localtime(&secs);
            printw("TIME: %s", asctime(timeInfo));
            getch();
            endwin();
        }
    }   
    return 0;
}

This code should create new console window and make time ls, but it doesn't. What is the problem?

4
  • What does it do? Have you tried calling open -a Terminal.app instead of just Terminal.app? Commented Mar 5, 2020 at 15:46
  • @RichardBarber, I'll trying to from one console window open another Commented Mar 5, 2020 at 18:17
  • You mean a separate instance of the Terminal.app. Commented Mar 6, 2020 at 19:11
  • You’ll also need the -n flag. Commented Mar 6, 2020 at 19:15

1 Answer 1

1

Use the command open -a -n Terminal.app to run a new instance of the app (even though one is already running).

Sign up to request clarification or add additional context in comments.

4 Comments

rly? I wanna do this from my c++ program, not from console.
Yes, don’t use the name of the app container to execute it. Use open.
You’ll have to parse it to suit
Just in case anyone else runs across this answer, I needed to change the command to open -n -a Terminal.app to get it to work. I also referenced ss64.com/osx/open.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.