IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++/CLI Discussion :

Double ouverture de la console lors de l'appel d'un .BAT


Sujet :

C++/CLI

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2014
    Messages : 5
    Points : 3
    Points
    3
    Par défaut Double ouverture de la console lors de l'appel d'un .BAT
    Bonjour,

    Je souhaite utiliser un soft C++ pour ouvrir un .bat , jusque la pas de soucis.
    Lors de l'appui sur un bouton, je lance un backgroundworker dans lequel j'utilise un process start info pour appeler mon fichier bat.

    Le problème, c'est que quand j'appuie sur mon bouton, 2 fenêtres de la console s'ouvrent, comme si mon thread arrière plan appelait deux fois mon fichier bat...

    A noter que si je lance directement le process start info depuis mon bouton, il s'ouvre normalement..

    Voici le code :
    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Threading;
     
     
    	/// <summary>
    	/// Description résumée de Form1
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	private:
     
    	System::Windows::Forms::Button^  button1;
    	System::ComponentModel::BackgroundWorker^  backgroundWorkerMACADRESS;
    	System::Windows::Forms::RichTextBox^  richTextBox1;
    	System::Diagnostics::Process^ process;
    	System::Diagnostics::ProcessStartInfo^ pInfo;
     
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			InitializeBackgoundWorker();
    			//
    			//TODO: ajoutez ici le code du constructeur
    			//
    		}
    	private:
     
       // Set up the BackgroundWorker object by attaching event handlers 
    		void InitializeBackgoundWorker()
    		{
    			backgroundWorkerMACADRESS->DoWork += gcnew DoWorkEventHandler( this, &Form1::backgroundWorkerMACADRESS_DoWork );
    			backgroundWorkerMACADRESS->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &Form1::backgroundWorkerMACADRESS_RunWorkerCompleted );
    			backgroundWorkerMACADRESS->ProgressChanged += gcnew ProgressChangedEventHandler( this, &Form1::backgroundWorkerMACADRESS_ProgressChanged );
    		}
     
    	protected:
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
     
    	protected: 
     
    	private:
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
    		/// le contenu de cette méthode avec l'éditeur de code.
    		/// </summary>
     
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->backgroundWorkerMACADRESS = (gcnew System::ComponentModel::BackgroundWorker());
    			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(50, 59);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(184, 46);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"Download MAC Adress";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// backgroundWorkerMACADRESS
    			// 
    			this->backgroundWorkerMACADRESS->WorkerReportsProgress = true;
    			this->backgroundWorkerMACADRESS->WorkerSupportsCancellation = true;
    			this->backgroundWorkerMACADRESS->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &Form1::backgroundWorkerMACADRESS_DoWork);
     
    			// 
    			// richTextBox1
    			// 
    			this->richTextBox1->Location = System::Drawing::Point(317, 50);
    			this->richTextBox1->Name = L"richTextBox1";
    			this->richTextBox1->Size = System::Drawing::Size(307, 276);
    			this->richTextBox1->TabIndex = 1;
    			this->richTextBox1->Text = L"";
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(646, 350);
    			this->Controls->Add(this->richTextBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"MainWindow";
    			this->ResumeLayout(false);
     
     
    		}
     
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    				 //Appel au backgroundworker pour le téléchargement de l'adresse mac
    				 // Start the asynchronous operation.
    					backgroundWorkerMACADRESS->RunWorkerAsync();
    					richTextBox1->Text= "Lancement Batch";
     
     
     
    			 }
    	private: System::Void backgroundWorkerMACADRESS_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) 
    			 {
     
    			 //Lancement du fichier .bat pour le téléchargement adresse mac
     
    					pInfo = gcnew System::Diagnostics::ProcessStartInfo;
    					pInfo->Verb = "open";//Action effectuée par le PSI
    					pInfo->FileName = "C:\\SondeDosto\\BatchFiles\\TestBatch.bat"; // Fichier a lancer
    					pInfo->UseShellExecute = true;
    					process = System::Diagnostics::Process::Start( pInfo );	
    			 }
    Auriez vous des idées pour remédier à cela ?

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Ca ressemble plus a du C# que du C++ ton code la c'est normal ?
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2014
    Messages : 5
    Points : 3
    Points
    3
    Par défaut
    Je suis parti d'exemples existants pour l'écrire, donc oui, c'est normal.
    Je suis un grand débutant en C++ (je précise, au cas ou ...)

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Citation Envoyé par wax78 Voir le message
    Ca ressemble plus a du C# que du C++ ton code la c'est normal ?
    il s'agit de C++.NET managé : C++/CLI
    http://msdn.microsoft.com/en-us/library/te3ecsc8.aspx
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  5. #5
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 074
    Points : 12 120
    Points
    12 120
    Par défaut
    N'avez-vous pas enregistré 2 fois l'handler d'évènement ?
    Utilisez un débuggeur.

    Vous débutez et vous faites directement du multi-threading ?

  6. #6
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Citation Envoyé par wax78 Voir le message
    Ca ressemble plus a du C# que du C++ ton code la c'est normal ?
    C'est du C++/CLI, donc c'est plus du C# que du C++.

    N'avez-vous pas enregistré 2 fois l'handler d'évènement ?
    Exactement, c'est là qu'est le problème: L'événement DoWork du BackgroundWorker est enregistré deux fois, il va donc lancer deux fois le .bat.

    D'ailleurs, j'ai du mal à comprendre pourquoi faire ça dans un BackgroundWorker si celui-ci n'attend pas la fin du batch...

    PS: @FAIDp, n'appelez pas ce langage "C++", c'est comme appeler du C++ "C". Il s'agit de langages différents.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  7. #7
    Candidat au Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2014
    Messages : 5
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    Merci de vos réponses, je n'avais pas fait attention à ce double appel..

    Oui, je fais du multi-threading car la tache principale va être beaucoup plus longue que prévu donc elle s’exécutera dans un autre thread, j'aurais donc un thread qui gérera la partie IHM et un autre qui gérera la tache principale ( c'est le plus simple je pense )

    Merci de l'info Médinoc, je t'avoue que j'avais un peu de mal a faire la différence..

Discussions similaires

  1. Ouverture d'une figure lors de l'appel à guihandles
    Par kap dans le forum Interfaces Graphiques
    Réponses: 3
    Dernier message: 21/10/2009, 07h38
  2. Masquer console lors de l'appel BATCH d'un JAR
    Par blastobi dans le forum Langage
    Réponses: 4
    Dernier message: 02/06/2006, 17h01
  3. J'ai un problème d'affichage console lors
    Par yvon_huynh dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 22/05/2006, 13h46
  4. multi ouverture de la console dans une boucle for
    Par jamesleouf dans le forum C++
    Réponses: 2
    Dernier message: 16/03/2006, 21h26
  5. FireFox ouverture automatique de "console javascript&qu
    Par troumad dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 25/10/2005, 17h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo