StefanK
StefanK

Reputation: 31

With Perl on Mac - How to open a new terminal and pass through commands

In Perl, on a Mac, I want to open a terminal window and pass on commands to that terminal.

In a Perl script, written for windows, the line

 system("gnome-terminal -- perl pullauta startthread $i");

Will start a new terminal window and execute the command "perl pullauta..."

When adopting this to Mac I do not get it how to send the commands to the new terminal.

I can open a new terminal window with

system ("open -n /System/Applications/Utilities/Terminal.app");

But I do not understand how to pass on the arguments / commands to the new window.

Any ideas? Given it needs to be executed from the Perl script, on a Mac.

Upvotes: 1

Views: 268

Answers (2)

StefanK
StefanK

Reputation: 31

In the end, what was the solution for us was to use system('the scripts name')

Essentially calling the script in the same terminal window and repeating that for all batch processes. It works in the sense that we get the output wanted, but not being able to see output texts from each process in parallel windows. As long as everything executes as expected this is a working solution.

Upvotes: 0

brian d foy
brian d foy

Reputation: 132822

You don't need the terminal to run a command. You can skip that by calling the command directly:

system 'echo', 'Hello there';

If you are trying to use a particular shell, that would be your command:

system 'zsh', ...

I suspect that you don't need the gnome-terminal either, but you haven't said why you are doing it that way. Maybe you have some weird situation. I suspect that since you are on Windows, that you are trying to avoid the default CMD shell and choosing the shell you want. It's a bit more complicated over there because you have a unixy tool (perl) adapted to work in Windows which you are then trying to adapt further to a unixy environment. When you are already on a unixy system, you just skip all that.

But, if you want to control Terminal for some reason, Apple wants you to do that through AppleScript:

osascript -e 'tell application Terminal to do script ...'

Upvotes: 3

Related Questions