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

Windows Forms Discussion :

Fonctionne en débug avec visual studio , mais pas avec cmd.exe


Sujet :

Windows Forms

  1. #1
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut Fonctionne en débug avec visual studio , mais pas avec cmd.exe
    Bonjour à tous,

    problème assez compliqué ici
    Je dois passer un argument (nom d'un fichier) à mon programme. Je fais d'abord du debugging avec VS, l'argument est bien pris en compte.

    Par contre si je lance mon programme via cmd.exe + non_du_fichier, il plante et j'obtiens une erreur dans l'event viewer Windows :

    Application*: myApp.exe
    Version du Framework*: v4.0.30319
    Description : le processus a été arrêté en raison d'une exception non gérée.
    Informations sur l'exception*: System.InvalidOperationException
    Pile*:
    à System.Diagnostics.Process.StartWithShellExecuteEx(System.Diagnostics.ProcessStartInfo)
    à System.Diagnostics.Process.Start()
    à WindowsFormsApplication1.Form1.LaunchScript(System.String, System.String)
    à WindowsFormsApplication1.Form1.MainGUI(System.String)
    à WindowsFormsApplication1.Form1..ctor()
    à Remote_Packager.Program.Main(System.String[])
    Form1.cs :
    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Diagnostics;
    using System.Management;
    using Microsoft.SqlServer.Server;
    using System.Drawing.Drawing2D;
    using System.Threading;
    using System.Collections;
     
     
     
    namespace WindowsFormsApplication1
    {
     
     
     
     
        public partial class Form1 : Form
        {
     
     
     
            public StreamReader tr;
            public StreamWriter tw;
            public string FileName;
            public int returnCode = 9;
            public string strCommandUpload;
            public string strCommandMonitor;
            public string strCommandDownload;
     
            // background colour
            protected override void OnPaint(PaintEventArgs e)
            {
                Rectangle rect = new Rectangle(0, 0, 984, 363);
     
                string CitrixColor1 = "#626669";
                //string CitrixColor2 = "#626669";
                LinearGradientBrush lgb = new LinearGradientBrush(rect, System.Drawing.ColorTranslator.FromHtml(CitrixColor1), Color.Black, 90);
     
                Graphics dc = e.Graphics;
     
     
                dc.FillRectangle(lgb, rect);
            }
     
     
     
            // Open Information System File
            public void OpenStreamFiles(string input, string output)
            {
     
                tr = new StreamReader(input);
                tw = new StreamWriter(output);
     
            }
     
     
            public Form1()
            {
                InitializeComponent();
                string[] Args = Environment.GetCommandLineArgs();
     
                if (Args.Length > 1)
                {
     
     
                    MainGUI(Args[1]);
                    this.Enabled = false;
     
     
                }
     
            }
     
     
            // when Run button is clicked
            public void bRun_Click(object sender, EventArgs e)
            {
     
                MainGUI(null);
     
            }
     
     
            public void MainGUI(string input)
            {
     
     
                strCommandUpload = "UploadFile.vbs";
                strCommandMonitor = "MonitorFile.vbs";
                strCommandDownload = "DownloadFiles.vbs";
     
                if (input == null)
                {
                    FileName = OpenFileDialog1.FileName;
                }
     
                else
                {
                    FileName = input;
                    MessageBox.Show(input);
                }
                    Process P = new Process();
     
                progressBar1.Maximum = 2;
                progressBar1.Value = 1;
                progressBar1.Value = 2;
     
     
     
     
                if (File.Exists(FileName))
                {
     
     
                    tabControl1.SelectTab(0);
                    LaunchScript(FileName, strCommandUpload);
     
                    int nbrAttempts = 0;
     
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork+=worker_DoWork;
     
                    BackgroundWorker workerDownload = new BackgroundWorker();
                    workerDownload.DoWork += workerDownload_DoWork;
     
                    worker.RunWorkerAsync();
     
                    worker.RunWorkerCompleted+=worker_RunWorkerCompleted;    
     
                    //2nd tab selection
                    pictureBox1.Visible = true;
                    tabControl1.SelectTab(1);
     
                    if (returnCode == 2)
                        workerDownload.RunWorkerAsync();
     
                 }
     
                else
                {
     
                    MessageBox.Show("File not found ");
                }
     
     
     
            }
     
            void workerDownload_DoWork(object sender, DoWorkEventArgs e)
            {
                returnCode = LaunchScript(FileName, strCommandDownload);
                Console.WriteLine("Downloading : " + returnCode);
            }
     
     
     
            void worker_DoWork(object sender, DoWorkEventArgs e)
            {
     
                int returnCode = 0;
     
     
                int nbrAttempts=0;
     
     
                returnCode = LaunchScript(FileName, strCommandDownload);
                Console.WriteLine("Downloading : " + returnCode);
     
     
                MessageBox.Show("Waiting on file...");
                do
                {
     
                    returnCode = LaunchScript(FileName, strCommandMonitor);
                    Console.WriteLine ("Monitoring : " + returnCode) ;
                    // if success we break the loop
                    if (returnCode == 2)
                    {
                        break;
                    }
     
                    nbrAttempts++;
     
                    // SLEEP 5min
                    Thread.Sleep(3000);
     
                }
     
                // aborts after 50min : timeout
                while (nbrAttempts < 10);
     
     
     
            }
     
     
            // when worker completed its run
            public void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
     
                // make sure the files are ready to be downloaded and download the packages
     
                // 2 success / 3 failure
                if (returnCode == 2)
                {
     
                    tabControl1.SelectTab(2);
                    returnCode = LaunchScript(FileName, strCommandDownload);
                    Console.WriteLine("Downloading : " + returnCode);
                }
     
                else
                {
                    MessageBox.Show("packages can't be downloaded due to a timeout");
                }
     
     
     
     
            }
     
            static int LaunchScript(string file, string script)
            {
     
     
                bool FTPisRunning = false;
     
                using (Process process = new Process())
                {
                    process.StartInfo.FileName = "cscript.exe";
                    process.StartInfo.Arguments = "//Logo " + script + " " + file;
     
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
     
                    StringBuilder output = new StringBuilder();
                    StringBuilder error = new StringBuilder();
     
                    using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
                    {
     
                        Thread.Sleep(1000);
     
                        process.OutputDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                outputWaitHandle.Set();
                            }
                            else
                            {
                                output.AppendLine(e.Data);
                            }
                        };
     
                        Thread.Sleep(1000);
     
                        process.ErrorDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                errorWaitHandle.Set();
                            }
                            else
                            {
                                error.AppendLine(e.Data);
                            }
                        };
     
     
     
     
                        process.Start();
                        FTPisRunning = true ;
                        Console.WriteLine( process.ToString());
     
     
                        Thread.Sleep(1000);
     
                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();
     
                        if (process.WaitForExit(10000) &&
                            outputWaitHandle.WaitOne(10000) &&
                            errorWaitHandle.WaitOne(10000))
                        {
     
                               do
     
                               {
     
                            Process[] pname = Process.GetProcessesByName("ftp");
     
                            if (pname.Length == 0)
                            {
                                Console.WriteLine("FTP has stopped");
                                FTPisRunning = false;
                            }
     
                            else
     
                                Console.WriteLine("FTP is running");
     
                                }    
     
                               while (FTPisRunning) ;
     
     
     
                            Console.WriteLine(process.ExitCode.ToString());
     
                        }
     
                        else
                        {
     
                            MessageBox.Show("Timeout");
                            // Timed out.
                        }
     
                        return process.ExitCode;
                    }
     
     
                }
     
            }
     
     
     
     
            private void button2_Click_1(object sender, EventArgs e)
            {
                DialogResult result = this.OpenFileDialog1.ShowDialog();
     
            }
     
     
        }
     
    }

  2. #2
    Membre éclairé Avatar de chamamo
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    588
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 588
    Points : 735
    Points
    735
    Par défaut
    Récupère tes arguments dans le Main.

  3. #3
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut
    ah ok merci
    Comment je les renvoie à mon form1.cs ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     static void Main(string[] args)
            {
     
     
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
               Application.Run(new Form1());
     
     
            }

  4. #4
    Membre éprouvé Avatar de sisqo60
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Février 2006
    Messages
    754
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 754
    Points : 1 188
    Points
    1 188
    Par défaut
    Tu peux changer le constructeur de form1, ou affecter des propriétés de form1.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    static void Main(string[] args)
            {
     
     
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 f1 = new Form1();
                if (args.Length > 0)
                f1.MaPropriete = args[0]
               Application.Run(f1);
     
     
            }
    ou

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    static void Main(string[] args)
            {
     
     
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1(args));
     
     
            }
    Bon dév.

  5. #5
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut
    j'ai changé la façon dont je récupère mon Args[0], mais mon appli se comporte toujours de la même façon..

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using WindowsFormsApplication1;
     
    namespace Remote_Packager
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                //disable GUI
     
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
     
     
     
                if (args.Length >= 1)
                {
     
                    string FileName = args[0];
                    MessageBox.Show(FileName);
                    Application.Run(new Form1(FileName));
     
                }
     
                else
     
                    Application.Run(new Form1());
     
     
            }
        }
    }

  6. #6
    Membre éprouvé Avatar de sisqo60
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Février 2006
    Messages
    754
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 754
    Points : 1 188
    Points
    1 188
    Par défaut
    c'est bien beau de changer la signature de ton constructeur de form1, mais il faut coder quelque chose dans ton formulaire pour qu'il puisse faire le travail que tu souhaites!

  7. #7
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut
    naturellement...

    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
     
     
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Diagnostics;
    using System.Management;
    using Microsoft.SqlServer.Server;
    using System.Drawing.Drawing2D;
    using System.Threading;
    using System.Collections;
     
     
     
    namespace WindowsFormsApplication1
    {
     
     
     
     
        public partial class Form1 : Form
        {
     
     
     
            public StreamReader tr;
            public StreamWriter tw;
            public string FileName;
            public int returnCode = 9;
            public string strCommandUpload;
            public string strCommandMonitor;
            public string strCommandDownload;
     
            // background colour
            protected override void OnPaint(PaintEventArgs e)
            {
                Rectangle rect = new Rectangle(0, 0, 984, 363);
     
                string CitrixColor1 = "#626669";
                //string CitrixColor2 = "#626669";
                LinearGradientBrush lgb = new LinearGradientBrush(rect, System.Drawing.ColorTranslator.FromHtml(CitrixColor1), Color.Black, 90);
     
                Graphics dc = e.Graphics;
     
     
                dc.FillRectangle(lgb, rect);
            }
     
     
     
            // Open Information System File
            public void OpenStreamFiles(string input, string output)
            {
     
                tr = new StreamReader(input);
                tw = new StreamWriter(output);
     
            }
     
     
            public Form1(string filename)
            {
     
                    InitializeComponent();        
                    MainGUI(filename);
                    this.Enabled = false;
     
                }
     
            public Form1()
            {
     
                InitializeComponent();
     
            }
     
     
            // when Run button is clicked
            public void bRun_Click(object sender, EventArgs e)
            {
     
                MainGUI(null);
     
            }
     
     
            public void MainGUI(string input)
            {
     
     
                strCommandUpload = "UploadFile.vbs";
                strCommandMonitor = "MonitorFile.vbs";
                strCommandDownload = "DownloadFiles.vbs";
     
                if (input == null)
                {
                    FileName = OpenFileDialog1.FileName;
                }
     
                else
                {
                    FileName = input;
                    MessageBox.Show(input);
                }
                    Process P = new Process();
     
                progressBar1.Maximum = 2;
                progressBar1.Value = 1;
                progressBar1.Value = 2;
     
     
     
     
                if (File.Exists(FileName))
                {
     
     
                    tabControl1.SelectTab(0);
                    LaunchScript(FileName, strCommandUpload);
     
                    int nbrAttempts = 0;
     
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork+=worker_DoWork;
     
                    BackgroundWorker workerDownload = new BackgroundWorker();
                    workerDownload.DoWork += workerDownload_DoWork;
     
                    worker.RunWorkerAsync();
     
                    worker.RunWorkerCompleted+=worker_RunWorkerCompleted;    
     
                    //2nd tab selection
                    pictureBox1.Visible = true;
                    tabControl1.SelectTab(1);
     
                    if (returnCode == 2)
                        workerDownload.RunWorkerAsync();
     
                 }
     
                else
                {
     
                    MessageBox.Show("File not found ");
                }
     
     
     
            }
     
            void workerDownload_DoWork(object sender, DoWorkEventArgs e)
            {
                returnCode = LaunchScript(FileName, strCommandDownload);
                Console.WriteLine("Downloading : " + returnCode);
            }
     
     
     
            void worker_DoWork(object sender, DoWorkEventArgs e)
            {
     
                int returnCode = 0;
     
     
                int nbrAttempts=0;
     
     
                returnCode = LaunchScript(FileName, strCommandDownload);
                Console.WriteLine("Downloading : " + returnCode);
     
     
                MessageBox.Show("Waiting on file...");
                do
                {
     
                    returnCode = LaunchScript(FileName, strCommandMonitor);
                    Console.WriteLine ("Monitoring : " + returnCode) ;
                    // if success we break the loop
                    if (returnCode == 2)
                    {
                        break;
                    }
     
                    nbrAttempts++;
     
                    // SLEEP 5min
                    Thread.Sleep(3000);
     
                }
     
                // aborts after 50min : timeout
                while (nbrAttempts < 10);
     
     
     
            }
     
     
            // when worker completed its run
            public void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
     
                // make sure the files are ready to be downloaded and download the packages
     
                // 2 success / 3 failure
                if (returnCode == 2)
                {
     
                    tabControl1.SelectTab(2);
                    returnCode = LaunchScript(FileName, strCommandDownload);
                    Console.WriteLine("Downloading : " + returnCode);
                }
     
                else
                {
                    MessageBox.Show("packages can't be downloaded due to a timeout");
                }
     
     
     
     
            }
     
            static int LaunchScript(string file, string script)
            {
     
     
                bool FTPisRunning = false;
     
                using (Process process = new Process())
                {
                    process.StartInfo.FileName = "cscript.exe";
                    process.StartInfo.Arguments = "//Logo " + script + " " + file;
     
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
     
                    StringBuilder output = new StringBuilder();
                    StringBuilder error = new StringBuilder();
     
                    using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
                    {
     
                        Thread.Sleep(1000);
     
                        process.OutputDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                outputWaitHandle.Set();
                            }
                            else
                            {
                                output.AppendLine(e.Data);
                            }
                        };
     
                        Thread.Sleep(1000);
     
                        process.ErrorDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                errorWaitHandle.Set();
                            }
                            else
                            {
                                error.AppendLine(e.Data);
                            }
                        };
     
     
     
     
                        process.Start();
                        FTPisRunning = true ;
                        Console.WriteLine( process.ToString());
     
     
                        Thread.Sleep(1000);
     
                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();
     
                        if (process.WaitForExit(10000) &&
                            outputWaitHandle.WaitOne(10000) &&
                            errorWaitHandle.WaitOne(10000))
                        {
     
                               do
     
                               {
     
                            Process[] pname = Process.GetProcessesByName("ftp");
     
                            if (pname.Length == 0)
                            {
                                Console.WriteLine("FTP has stopped");
                                FTPisRunning = false;
                            }
     
                            else
     
                                Console.WriteLine("FTP is running");
     
                                }    
     
                               while (FTPisRunning) ;
     
     
     
                            Console.WriteLine(process.ExitCode.ToString());
     
                        }
     
                        else
                        {
     
                            MessageBox.Show("Timeout");
                            // Timed out.
                        }
     
                        return process.ExitCode;
                    }
     
     
                }
     
            }
     
     
     
     
     
     
     
            private void button2_Click_1(object sender, EventArgs e)
            {
                DialogResult result = this.OpenFileDialog1.ShowDialog();
     
            }
     
     
        }
     
    }

  8. #8
    Membre éprouvé Avatar de sisqo60
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Février 2006
    Messages
    754
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 754
    Points : 1 188
    Points
    1 188
    Par défaut
    On s'est attelé à faire en sorte de passer ton argument à ton form, mais le problème n'était pas là!

    A vrai dire, je n'ai ni le temps ni l'envie de décortiquer ton code, met des try/catch dans tes fonctions et log tes erreurs dans un fichier comme ça tu pourras nous en dire plus sur l'exception.

    InvalidOperationException, c'est très vague comme exception. Mais à mon avis c'est dans ta fonction lauchscript...

  9. #9
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut
    Bon j'ai placé un wscript dans le vbs que je lance , et appelé le tout avec wscript.exe (au lieu de cscript). J'obient une belle erreur "can't find the file..."

    Donc j'ai mis l'@ en absolu , car c'était un problème de working directory
    Merci en tout cas!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 04/02/2013, 16h28
  2. [ZF 1.10] Clause where qui fonctionne avec type int mais pas avec type String
    Par shadypierre dans le forum Zend_Db
    Réponses: 5
    Dernier message: 30/04/2010, 13h00
  3. Réponses: 1
    Dernier message: 12/05/2009, 15h14
  4. Réponses: 7
    Dernier message: 19/02/2008, 15h30
  5. Mon script fonctionne avec un bouton, mais pas avec l'image!
    Par julien.63 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 12/04/2006, 16h26

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