[Gambas-user] shell

MinnesotaJon nicholso at ...2533...
Mon Dec 2 17:08:42 CET 2013


Maybe I'm not understanding the problem, but "sudo" always wants a password,
right?  In which case you have to feed it a password with the Exec or Shell
command.  I'm not a shell script expert (just learning), but I assume that
the string would look like this:

Exec [system.shell, "sudo sh -c 'echo out
/sys/class/gpio/gpio27/direction'<< EOF\nmypassword\nEOF"] 
where you have already dimensioned and set the value of "mypassword" in your
code.

If you have dimensioned a variable like "strShellResponseString", you will
be able to display a response from sudo in your program, if the password is
incorrect:
Exec [system.shell, "sudo sh -c 'echo out
/sys/class/gpio/gpio27/direction'<< EOF\nmypassword\nEOF"] TO
strShellResponseString

note:  My additional code is a "here document" code block.  "<<" feeds a
command list to an interactive program or a command, like sudo.  "EOF" means
end-of-file, but it also terminates input from stdin.  The newline escape
code "\n" is needed before and after the password variable, to place the
password where sudo expects it, after a linefeed from stdin, followed by
another linefeed.  And then the second "EOF" terminates this input, which
allows sudo to evaluate the password and either execute the sh command, or
give an error message if the password is wrong.  No extra spaces in all of
this, or they'll be interpreted as part of the code!



--
View this message in context: http://gambas.8142.n7.nabble.com/shell-tp44500p44508.html
Sent from the gambas-user mailing list archive at Nabble.com.




More information about the User mailing list