Recent

Author Topic: [solved] tprocess under linux  (Read 3502 times)

cappe

  • Full Member
  • ***
  • Posts: 191
[solved] tprocess under linux
« on: September 17, 2018, 10:51:34 am »
hello,
  I have to execute the following instructions in tprocess: I manually write it like this:

sudo su
command

How can I run this batch inside a TProcess?

Thank you

P.S. I tried to write this way but it does not work 'sudo su -c "command"', but it does not work.



« Last Edit: September 21, 2018, 09:01:48 am by cappe »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: tprocess under linux
« Reply #1 on: September 17, 2018, 11:19:31 am »
Why do you need both sudo and su ? Just for the shell? Sudo has -s that maybe can be used to combine this.

I haven't tested, but I think something like this could work:

Code: Pascal  [Select][+][-]
  1. Runcommand('/bin/sh',['-c','echo ' + sPass  + ' | sudo -S  "su -c command"'],outputstr,[postderrtooutput]);

if you don't need password for sudo you can simplify to

Code: Pascal  [Select][+][-]
  1. Runcommand('sudo',['"su -c command"'],outputstr,[postderrtooutput]);

or even


Code: Pascal  [Select][+][-]
  1. Runcommand('sudo',['-c','command'],outputstr,[postderrtooutput]);

cappe

  • Full Member
  • ***
  • Posts: 191
Re: tprocess under linux
« Reply #2 on: September 17, 2018, 11:39:31 am »
there is the password and it does not work.

I'm a beginner with linux and the command to run, I install it with sudo insmod, so it needs to root.
The first example gives me the password and does not execute the command

Even launching the script written in runcommand from shell teminal does not work.

Alternatives.
« Last Edit: September 17, 2018, 11:52:52 am by cappe »

cappe

  • Full Member
  • ***
  • Posts: 191
Re: tprocess under linux
« Reply #3 on: September 18, 2018, 05:10:31 pm »
marcov

thanks  for the example

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: tprocess under linux
« Reply #4 on: September 19, 2018, 04:53:13 am »
Dou you need to enter the password?

I remember something about the program "expect" to automate login.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

cappe

  • Full Member
  • ***
  • Posts: 191
Re: tprocess under linux
« Reply #5 on: September 20, 2018, 09:17:03 am »
I need the password.

Can you give me an example?

balazsszekely

  • Guest
Re: tprocess under linux
« Reply #6 on: September 20, 2018, 09:34:37 am »
@cappe

Quote
I need the password.
Can you give me an example?
Did you try this: http://wiki.freepascal.org/Executing_External_Programs#Redirecting_input_and_output_and_running_under_root ?

cappe

  • Full Member
  • ***
  • Posts: 191
Re: tprocess under linux
« Reply #7 on: September 21, 2018, 08:51:26 am »
It works. I had made a mistake.

 

TinyPortal © 2005-2018