Bonjour,
j'essaye depuis un moment déjà à changer le hostname d'un Raspberry avec un interface graphique qui a d'autres fonctions.
d'ici : https://pricklytech.wordpress.com/20...-command-line/
je sais le commande que je souhaite passer:
à la main dans une console ça marche nickel, après on reboot et c'est plié
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 #change hostname in /etc/hosts & /etc/hostname sudo sed -i "s/$oldhostn/$newhost/g" /etc/hosts sudo sed -i "s/$oldhostn/$newhost/g" /etc/hostname
j'ai lu et relu http://wiki.lazarus.freepascal.org/E...ing_under_root
mais je n'arrive pas à faire fonctionner mon code:
note : hoststring est un variable string globale initialisée au lancement de l'appli qui garde le hostname
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 procedure TForm1.PI2iniClick(Sender: TObject); Var FileIni : TIniFile; lig:string; Proc: TProcess; PW: String; begin FileIni:=TIniFile.Create('/home/pi/Raspi.ini'); // Ouvre ou crée le fichier Try // Sauvegarde SN et Hostname dans fichier ini FileIni.WriteString('Raspi', 's/n', lab_snpi.Caption); FileIni.WriteString('Raspi', 'hostname', ed_hostname.Text); // la il faudra mettre Ã* jour les fichiers linux Proc := TProcess.Create(nil); Proc.CommandLine := 'sudo -S /bin/sed -i "s/'+hoststring+'/'+ed_hostname.Text+'/g" /etc/hosts'; // -S causes sudo to read the password from stdin. proc.Options := [poWaitOnExit, poUsePipes]; Proc.Execute; //start it. sudo will now probably ask for a password // write the password to stdin of the sudo program: PW := 'PWRootpi' + LineEnding; Proc.Input.Write(PW[1], Length(PW)); finally FileIni.Free; Proc.Free; end;
je dois louper un truc surement
Si quelqu'un a une idée merci de son aide
Zeg
Partager