All Things Ubuntu Library Wiki
Ubuntu dedicated Object Pascal libraries
Brought to you by:
krisjacewicz
Executes specified command via bash shell. On non UNIX systems it will do nothing, but will still compile, It is blocking, so be careful not to pass a command that will wait for an input that will not happen (see example). This call does not handle output capturing, only the exit code. For capturing output check routines in the [ATUprocess] unit instead.
Function Bash(cmd: string): integer;
Returns the exit code of the executed command or -1 if the specified command was not recognized as a valid shell command.
//this will print files and folders in the current folder to the stdout: bash('ls'); //this will copy a file: bash('cp /etc/apt/sources.list ~/'); //this will remove a directory along with all its content: bash('rm -r ~/SomeFolder'); //This one is even better, because the one above might use interactiv way to ask user //to confirm deleting certain files/folders, and since we call it programatically there is //no user to to answe the prompt and the command above could actually stay active forever, //and since this API is blocking, it could freze the application, so much better would be: bash('rm -f -r ~/SomeFolder'); //but in case a command still allows for a scenario when a user prompt could freeze the call, //you can even send the entire shell command into a background and return immediately: bash('rm -f -r ~/SOmeFolder &'); //the above call may still stay active until the end of you appliction's execution, but at least //it will not freeze the app, because it will send shell command into the background and return. //this is adviced AGAINST: bash('sudo touch /etc/apt/sources.list'); //instead, if you must use: bash('gksudo touch /etc/apt/sources.list'); //because sudo is an interactive shell command, and it would not really work for us, //while gksudo would actually show a GUI prompt for password, so that user could //use it and allow the shell command for actually receiving the input and it //could finish and return.