In their simplest form, do programs just run terminal commands?

Say as an example in a program it allows me select one folder and also duplicate it to an additional area, on a really standard degree is that application running commands that I could run in incurable or is it making use of some inner OS API to make that action?

Please save me any kind of savage feedbacks ; I'm simply interested and also entirely mindful it can be regarded as an inquiry a 13 - year - old would certainly ask.

2022-06-07 14:38:56
Source Share
Answers: 5

One of the wonderful suggestions behind Unix is (was) that if you obtained a suggestion for a program, after that you would certainly first write it as a shell manuscript - basically calling a collection of commands.

After that, if the program confirmed to be valuable, you can improve its user interface, have customers examine it, and also ultimately, when you were encouraged it deserved it, write a "real" program.

This, certainly, was prior to icon took control of, so a "program" below is a CLI command by itself.

You still see this strategy in some modern-day programs, specifically if they show system details. Intend to construct a straightforward application to detail all documents in a folder? Simply run ls -al, parse the outcome and also show it a table. Enjoy with the numerous parameters, and also you have your product for variation 2.0

2022-06-07 15:07:00

One class of programs that run incurable commands (despite the fact that all of it beginnings with an API call) is the incorporated program - growth settings such as eclipse or Xcode. The collection of devices needed for program growth is much too huge to be had in, and also kept for, an IDE. Rather, it constructs a makefile (a sort of manuscript) and also runs it with unix 'make' (or an equal) to tip via the compile, link, load, and also debug procedure. Make, subsequently, runs the compiler, linker, etc utilizing their command - line user interfaces. This allows the IDE be reasonably independent of the device - set picked by the designer, and also aloof to updates to the devices.

2022-06-07 15:06:01

I'm worried the solution is "it depends, yet generally the second." Actually, also if a GUI program is running terminal commands, it runs them by calling an API.

A program that is merely a checklist of terminal commands is called a shell manuscript. Such programs can run in Mac OS X, yet they need to either run in a Terminal window or release a program that makes use of the GUI if you intend to see their result. Various other programs can call command line programs via inner APIs.

While the majority of growth inquiries are off - subject for this website, one instance that is in fact on - subject entails running Automator.

One alternative within the checklist of inner commands a program developed in Automator can call is the capacity to call a shell manuscript, or checklist of Terminal commands. Yet that is simply of of several alternatives readily available within its inner API.

2022-06-07 15:05:43

Conceptually, it constantly makes use of OS API - the inquiry is just in what means. There are basically 3 alternatives.

  1. making use of reduced - degree OS API (system calls) straight. In your instance the job is fairly entailed: get the checklist of things in the folder, examine the type (folder, documents ), for each and every of them create the equivalent thing in the target folder, for documents read the web content from the resource, contact the target documents etc Since the job is so intricate, it is very easy to get glitch, so most applications will certainly prevent this.

  2. make use of a collection (API) that streamlines the job. As an example the Apple Cocoa structure gives NSFileManager class with the copyItemAtPath:toPath:error method which does all the grunt work making use of reduced - degree OS API, so the application does not require to make use of reduced - degree API itself yet can rely upon something that calls for much less job and also is constantly existing in the system. Additionally Apple is most likely to see to it that it functions well.

  3. make use of an exterior procedure to do the job. In this instance the exterior procedure will certainly be making use of among both approaches over to do the job. The application needs to start such procedure, check it and also wait till it is done. It is most likely that such procedure can be run as a command line device, so this would likely be a command you can run in Terminal. It is not assured, yet really feasible.

The majority of applications will certainly make use of alternative 2. due to the fact that it is extra straightforward than 1. and also extra secure and also reliable than 3. In order to run an exterior procedure you require to set it up effectively and also you have no control over what it does. As an example it is much tougher to identify just what failed in instance of a failing and also it is tough to recognize what it is doing (as an example show progression). That is why most of the times programmers will likely pick alternative 2, yet there is no warranty. A remarkable instance are applications that make use of shell manuscripts for modification - such as installers.

Advanced customer note: you can make use of dtrace center of OS X to figure out what a certain application is doing. As an example, you can examine any kind of procedures it is generating so you would certainly see the devices it is making use of (see execsnoop).

2022-06-07 15:05:31

Applications can run CLI commands to execute a particular job, and also some in fact do ; yet as a result of performance concerns, specialist application programmers stay clear of running the command and also instead make use of the APIs that the command makes use of to execute the job called for.

2022-06-07 15:04:43