Comment intégré mon textbox en c#

FRVGH - Modifié le 24 janv. 2024 à 02:32
Whismeril Messages postés 19041 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 mai 2024 - 24 janv. 2024 à 10:01

Bonjour,

J'aimerais intégré mon textbox a ma commande curl

le textbox dois etre a la place de frank

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void Button1_Click(object sender, EventArgs e)
        {

            string usernameT = username.Text;

            string curlCommand = "curl";
            string curlArguments = "-X POST https://cloud-dev..fr/ocs/v1.php/cloud/users -d userid=\"Frank\" -d password=\"frankspassword@\" -H \"OCS-APIRequest: true\"";

            ExecuteCommand(curlCommand, curlArguments);
        }

        private void ExecuteCommand(string command, string arguments)
        {
            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardError = true
            };

            using (Process process = new Process())
            {
                process.StartInfo = processStartInfo;
                process.Start();

                process.StandardInput.WriteLine($"{command} {arguments}");
                process.StandardInput.Flush();
                process.StandardInput.Close();

                string output = process.StandardOutput.ReadToEnd();
                string errors = process.StandardError.ReadToEnd();

                process.WaitForExit();

                if (string.IsNullOrWhiteSpace(errors))
                {
                    MessageBox.Show("Sortie de la commande : " + output, "Commande exécutée avec succès");
                }
                else
                {
                    // MessageBox.Show("Erreurs : " + errors, "Erreur lors de l'exécution de la commande");
                }
            }
        }


    }
}

Je vous remercie beaucoup pour votre aide .
Windows / Firefox 115.0

1 réponse

Whismeril Messages postés 19041 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 mai 2024 912
24 janv. 2024 à 10:01

Bonjour

regarde du côté des différentes méthode de concanténation de chaines 

  • string.format
  • stringbuilder
  • interpolation de chaine
  • etc

A noter tout de même que la concaténation est une notion de base dans n'importe quelle language, qu'il aurait fallu apprendre avant de te lancer dans une application complexe 


0