Impossible de paramétrer un argument pour process cmd.exe

cs_Twetty56 Messages postés 8 Date d'inscription samedi 18 octobre 2003 Statut Membre Dernière intervention 18 août 2020 - 16 août 2020 à 09:06
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 - 18 août 2020 à 19:27
Bonjour a tous
depuis 3 jours je suis bloque

je cherche a passer un argument pour un process cmd.exe

j'ai trouvé tous les code voulu

mais mon argument retourne toujours une erreur et ne s’exécute pas

voici l'argument qui marche en manuel

C:\Programme\EBP\Invoicing12.2FRFR40\EBP.Invoicing.Application.exe /Gui=false /Database=c:\Users\THIERRYAIS\Documents\DOSSIER.ebp;EBPSDK /Import="D:\CLIENT\DOSSIER\FTP\EXPEDITION\IMPORTEBP\CR_PRE20200611145811122.CSVEBP.csv;TemporarySaleInvoices;FACTURE CLD"

Cette commande ajoute systématiquement 2 "" dans la variable texte de l'argument

C:\Programme\EBP\Invoicing12.2FRFR40\EBP.Invoicing.Application.exe /Gui=false /Database=c:\Users\THIERRYAIS\Documents\DOSSIER.ebp;EBPSDK /Import=""D:\CLIENT\DOSSIER\FTP\EXPEDITION\IMPORTEBP\CR_PRE20200611145811122.CSVEBP.csv;TemporarySaleInvoices;FACTURE CLD"""


et je ne parviens pas a obtenir un bon fonctionnement

Merci a tous

pour information cet argument me permets de faire des import de données dans un logiciel

7 réponses

vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
16 août 2020 à 15:33
bonjour
tu dis : je cherche a passer un argument pour un process cmd.exe

Et si tu nous montrais comment tu le codes ce Process ?
Pour poster du code voir ceci : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
0
cs_Twetty56 Messages postés 8 Date d'inscription samedi 18 octobre 2003 Statut Membre Dernière intervention 18 août 2020
Modifié le 16 août 2020 à 22:33
Voici le code

      ''' <summary>
    ''' Extension method to run string as CMD command.
    ''' </summary>
    ''' <param name="command">[String] Command to run.</param>
    ''' <param name="ShowWindow">[Boolean](Default:False) Option to show CMD window.</param>
    ''' <param name="WaitForProcessComplete">[Boolean](Default:False) Option to wait for CMD process to complete before exiting sub.</param>
    ''' <param name="permanent">[Boolean](Default:False) Option to keep window visible after command has finished. Ignored if ShowWindow is False.</param>

    Public Sub RunCMD(command As String, Optional ShowWindow As Boolean = False, Optional WaitForProcessComplete As Boolean = False, Optional permanent As Boolean = False)

        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()

        pi.Arguments = command
        pi.FileName = "cmd.exe"
        pi.Verb = "runas"
        pi.CreateNoWindow = Not ShowWindow
        If ShowWindow Then
            pi.WindowStyle = ProcessWindowStyle.Normal
        Else
            pi.WindowStyle = ProcessWindowStyle.Hidden
        End If
        pi.UseShellExecute = False
        p.StartInfo = pi
        p.Start()
        If WaitForProcessComplete Then Do Until p.HasExited : Loop

    End Sub




et la génération de l'argument a partir d'un fichier après avoir fait des tests en le créant sur une variable string et des paramètres

           'Lecture Fichier Origine
            sr = New StreamReader("D:\DEVELOPPEMENT\BL\cmd.txt", System.Text.Encoding.UTF8)

            'met le contenu dans une variable texte
            m_ContenuFichier = sr.ReadToEnd

            R = Split(m_ContenuFichier, vbLf)

            'Ferme le fichier
            sr.Close()

            m_ContenueCommande = R(0)

            m_AncienFichier = "CR_PRE20200611145811122.CSVEBP.csv"

            m_NouveauFichier = Strings.Replace(strFichier, "D:\CLIENT\DOSSIER\FTP\EXPEDITION\", "")

            m_NouveauFichier = Strings.Left(m_NouveauFichier, Strings.Len(m_NouveauFichier) - 4)

            m_NouveauFichier = m_NouveauFichier + "EBP.csv"

            m_ContenueCommande = Strings.Replace(m_ContenueCommande, m_AncienFichier, m_NouveauFichier)

            m_ContenueCommande = Strings.Replace(m_ContenueCommande, Chr(34) + Chr(34), Chr(34))

            'RunCMD(m_ContenueCommande)



--voici le contenu du fichier
C:\Programme\EBP\Invoicing12.2FRFR40\EBP.Invoicing.Application.exe /Gui=false /Database=c:\Users\THIERRYAIS\Documents\DOSSIER.ebp;EBPSDK /Import="D:\CLIENT\DOSSIER\FTP\EXPEDITION\IMPORTEBP\CR_PRE20200611145811122.CSVEBP.csv;TemporarySaleInvoices;FACTURE CLD"

Merci de vos réponse

Twetty56[blue]
0
Whismeril Messages postés 19024 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 18 avril 2024 656
16 août 2020 à 22:15
Pour que ce soit lisible, il faut copier coller le code, dans les balises, pas après
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
17 août 2020 à 09:17
Bonjour
Un code plus clair pour RunCMD
Public Sub RunCMD(command As String, Optional ShowWindow As Boolean = False, Optional WaitForProcessComplete As Boolean = False, Optional permanent As Boolean = False)

        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo With {
            .Arguments = command,
            .FileName = "cmd.exe",
            .Verb = "runas",
            .CreateNoWindow = Not ShowWindow,
            .UseShellExecute = False,
            .WindowStyle = If(ShowWindow = True, ProcessWindowStyle.Normal, ProcessWindowStyle.Hidden)
        }
        p.StartInfo = pi
        p.Start()
        If WaitForProcessComplete = True Then
            Do Until p.HasExited = True
            Loop
        End If

    End Sub


Par contre pour la génération de l'argument
1) Utilisez
Environment.Newline
pour le Split à la place de
vbLf

2) La génération de l'argument m'échappe . Pouvez-vous expliquer plus clairement ?
0
cs_Twetty56 Messages postés 8 Date d'inscription samedi 18 octobre 2003 Statut Membre Dernière intervention 18 août 2020
17 août 2020 à 20:40
Merci de ta réponse

voici le détail de l'argument

ouverture du programme avec une fenêtre masquée

C:\Programme\EBP\Invoicing12.2FRFR40\EBP.Invoicing.Application.exe /Gui=false

ouverture du dossier avec l'utilisateur EBPSDK (Utilisateur pour utilsé le SDK EBP)

/Database=c:\Users\THIERRYAIS\Documents\DOSSIER.ebp;EBPSDK

Import du fichier donnant le chemin + 1 parùètre pour lui indique quel type d'import est à faire + le format d'import pour ce type

/Import="D:\CLIENT\DOSSIER\FTP\EXPEDITION\IMPORTEBP\CR_PRE20200611145811122.CSVEBP.csv;TemporarySaleInvoices;FACTURE CLD"

j'espère que c'est plus clair merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
18 août 2020 à 13:01
Bonjour
Ca commence à être un peu plus clair
Reprenons
 'Lecture Fichier Origine
            sr = New StreamReader("D:\DEVELOPPEMENT\BL\cmd.txt", System.Text.Encoding.UTF8)
            'met le contenu dans une variable texte
            m_ContenuFichier = sr.ReadToEnd
            R = Split(m_ContenuFichier, vbLf) ' 3 lignes du fichier
            'Ferme le fichier
            sr.Close()
            m_ContenueCommande = R(0) ' ouverture du programme avec une fenêtre masquée 
            m_AncienFichier = "CR_PRE20200611145811122.CSVEBP.csv" ' présent dans la troisième ligne
            ' A partir de là je ne comprends plus rien : explique
            ' C'est quoi strFichier ?
            m_NouveauFichier = Strings.Replace(strFichier, "D:\CLIENT\DOSSIER\FTP\EXPEDITION\", "") 
            m_NouveauFichier = Strings.Left(m_NouveauFichier, Strings.Len(m_NouveauFichier) - 4)
            m_NouveauFichier = m_NouveauFichier + "EBP.csv"
            m_ContenueCommande = Strings.Replace(m_ContenueCommande, m_AncienFichier, m_NouveauFichier)
            m_ContenueCommande = Strings.Replace(m_ContenueCommande, Chr(34) + Chr(34), Chr(34))


Le fichier D:\DEVELOPPEMENT\BL\cmd.txt contient la commande en manuel qui fonctionne si je comprends bien . Tu veux ensuite à partir de ce fichier pouvoir créer une commande avec un autre paramètre pour le fichier à importer si je comprends bien .
0
cs_Twetty56 Messages postés 8 Date d'inscription samedi 18 octobre 2003 Statut Membre Dernière intervention 18 août 2020
18 août 2020 à 14:11
Merci vb95

tu as tout compris

je l'ai fait par un fichier pour tester car en le construisant sur une variable texte je n'y suis pas parvenu non plus

et surtout comme je n'ai aucun retour je ne sais pas pourquoi

--je possede aussi des procèdure en c# fourni par l'editeur
que j'ai mis en deuxième projet (il a un namespace)
mais je ne parviens pas a les lier a mon projet

que je les mettes en référence ou pas
impossible de les voir dans ce projet
Twetty56[blue]
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
18 août 2020 à 19:27
Bonjour
en utilisant 3 variables
Dim Fichier as String = "Le fichier à utiliser avec son chemin complet"
Dim Application as String = "C:\Programme\EBP\Invoicing12.2FRFR40\EBP.Invoicing.Application.exe /Gui=false"
Dim Utilisateur as String = "/Database=C:\Users\THIERRYAIS\Documents\DOSSIER.ebp;EBPSDK"
Dim Parametre as String = "/Import=""" & Fichier & ";TemporarySaleInvoices;FACTURE CLD"""

Ensuite tu regroupes Application , Utilisateur et Parametre pour construire ta commande
Vu que la commande finale contient des "" il fait les doubler ( une fois après /Import= et une fois après FACTURE CLD
J'espère avoir compris .
0
Rejoignez-nous