Recent

Author Topic: Button opens terminal (Linux) "solved"  (Read 1673 times)

ortegahernandes

  • New Member
  • *
  • Posts: 19
Button opens terminal (Linux) "solved"
« on: December 14, 2024, 01:40:19 pm »
I believe it is simple (but I don't know how to do it lol).

What command opens the Linux terminal?
I actually need to create a button and when I click on it in the terminal, the following command will appear.

sudo adduser "username" dialout
« Last Edit: December 14, 2024, 09:07:58 pm by ortegahernandes »

Hartmut

  • Hero Member
  • *****
  • Posts: 891
Re: Button opens terminal (Linux)
« Reply #1 on: December 14, 2024, 02:01:52 pm »
You can use e.g. class 'TProcess' to call either '/bin/bash' or to execute a linux command.

Please see http://wiki.freepascal.org/Executing_External_Programs

If you need more help please let me know.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8132
Re: Button opens terminal (Linux)
« Reply #2 on: December 14, 2024, 04:02:32 pm »
Sudo might be tricky though, because it is fairly careful where it gets the user's credentials from.

Around three years ago I contributed a patch which allowed the "run after" command to be run by root etc. It was ignored because it wasn't portable to Windows...

Updated: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38608 for Lazarus 2.2.4 + FPC 3.2.2.

The complicating factor was that in order in order to get sudo to work properly I had to use the --askpass option, with the prerequisite of identifying a suitable implementation of askpass installed on the development system.

I used it fairly heavily at the time, since I was doing things which required elevated POSIX capabilities.

MarkMLl
« Last Edit: December 14, 2024, 04:22:31 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ortegahernandes

  • New Member
  • *
  • Posts: 19
Re: Button opens terminal (Linux) ""Solved""
« Reply #3 on: December 14, 2024, 09:05:57 pm »
First of all, I would like to thank you both for your answers.

I realized that this would be a lot of work for something almost trivial, it wasn't worth the effort.

The only thing I wanted was for the terminal window to open with the command ready, but each distro uses a different terminal and I also realized that I would have to stack the code with bash.

I'll just leave a hint to give the command according to the distribution.

The use would be for industrial automation software, a modbus simulator that I made available for download if anyone wants to see it, here it is:

http://scanbus.com.br
« Last Edit: December 14, 2024, 09:07:36 pm by ortegahernandes »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8132
Re: Button opens terminal (Linux) "solved"
« Reply #4 on: December 14, 2024, 09:36:48 pm »
Seems reasonable under the circumstances. I don't know whether you could get your program to run the command on the user's behalf (find the bit I'd patched in the IDE, duplicate my patch, restart the program) or if as well as running  sudo adduser...  he'd have to logout/login to get the changed group membership to stick.

In any event I congratulate you on actually /knowing/ about the dialout group, rather than (as so many do) saying "run this as root" :-)

Hmm, I wonder. I've not tried this, but if your program used a variation on my patch to apply the relevant POSIX capability to its own binary, then restarted itself (by invoking the binary and exiting) it might /just/ be possible to get access to the port without having to logout/login.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Button opens terminal (Linux) "solved"
« Reply #5 on: December 16, 2024, 02:29:52 am »
I believe it is simple (but I don't know how to do it lol).

What command opens the Linux terminal?
I actually need to create a button and when I click on it in the terminal, the following command will appear.

sudo adduser "username" dialout


Hello @ortegahernandes,

I have attached a fully working demo zip file that does what you want to do and will help you get started.  The first attached screenshot shows you three available options.
1.Show Hint In Terminal
2.Execute Shell Command
3.Show Valid Login Shells For Your Distro

The second screenshot shows 'all' options active. The first Terminal shows the hint you wanted, the second Terminal will execute any command you give it and it shows a list of valid logins for the distro.

Another useful thing to know is if you type
Code: Text  [Select][+][-]
  1. echo $$
in And in a Terminal type
Code: Text  [Select][+][-]
  1. cat /proc/$$/comm
that will show you which terminal is active. Hope this will help. TRy to find out about what the '$$' is for :)

ortegahernandes

  • New Member
  • *
  • Posts: 19
Re: Button opens terminal (Linux) "solved"
« Reply #6 on: December 19, 2024, 01:44:32 am »
I'm a bit speechless...

Thank you very much Aruna, it seems exactly what I needed . :)

I'll take a look at it over the weekend and try to implement it.

 :D
« Last Edit: December 19, 2024, 11:39:13 pm by ortegahernandes »

 

TinyPortal © 2005-2018