How to create a Script inside a program in the terminal?

Asked

Viewed 390 times

1

I’m looking to develop a script to automate some repetitive tasks I’ve been doing on the terminal. However. I can only create Scripts for Commands directly in the terminal, not for commands within the program.

Imagem do programa onde desejo colocar o Script

How can I create an SH that will act within this program?

1 answer

3


I understand your question, but in my opinion your approach is wrong.

I can not see your image and also Oce did not quote the programming language, but this was already a doubt of mine and I will record here an answer to who it may interest if the language is C or C++.

No scripts are created on executables, if system calls are used to directly execute commands.

For this there are some alternatives, the simplest is to use within the executable a call to system().

A banal example would be:

#include <stdlib.h>

int main (int argc, char *argv[])
{
    system(argv[1]);
    return 0;
}

Try passing some argument to the executable, example:

./binario "ls -l"

There are also other calls that do this with the use of popen() and pclose(), depend solely on the stdio.h.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.