Send a command to the Terminal via C ++

3

How do I send a code to the terminal?

For example: on a graphical screen where I type the name of a folder, and it sends to the terminal a mkdir NomePasta ? (Of course, there will be other functionalities, like running programs for example, but I just need to know how to send the command).

    
asked by anonymous 13.08.2014 / 15:14

2 answers

3

You can use the system function. However I must warn you to be very careful with it. Firstly why this command will send the argument directly to the terminal, which will run according to the user environment. So maybe the command does not do what you expect it to do. If an alias has been defined for mkdir , or if the executable itself has changed.

Another problem is that with the argument given by the user. If it says that the folder name is documentos && rm -rf / , you will cause damage to the computer if you run the command like that. It is something very similar to SQL Injection (search).

The solution is to do what you want to do with the command, without using the command. For example, if you want to create a directory, how about using the function mkdir that is perfectly secure and does exactly what the documentation says it does? In short: look for alternatives.

    
13.08.2014 / 19:01
2

13.08.2014 / 15:25