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

VB.NET Discussion :

Execution, capture et envoie de données à un programme externe.


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 2
    Par défaut Execution, capture et envoie de données à un programme externe.
    Bonjour,

    Etant complètement nouveau au VB.NET (4 jours), je me retrouve devant un problème que je n'arrive pas à résoudre. Je sollicite donc un peu d'aide pour m'éclairer.
    Entrons dans le vif du sujet. Je dois développer une interface utilisateur qui leur permettra de soumettre des calculs d'une application (abaqus) à un cluster de calcul (hpc 2008).L'application fonctionnent déja en mode console, mais les utilisateurs n'en sont pas satisfait, ils trouvent cela trop compliqué. Pour soumettre des calculs depuis leur machine, voici ce dont ils ont besoin :
    • 1 map réseau pointant sur l'application (abaqus)
    • 1 map réseau pointant sur un stockage pour héberger leurs fichiers. L'application ne prend pas en compte les path locaux non convertibles en en UNC.

    Afin de soumettre un calcul, l'utilisateur passe une commande de type :
    y:\version_de_abaqus\abaqus.exe -j mon_job -cpus 8
    J'ai donc tenté de créer une form ou l'utilisateur soumet un fichier à calculer, la version de l'application qu'il souhaite utiliser, le nombre de cœurs qu'il souhaite utiliser. Les maps sont alors montés automatiquement, le fichier est copié sur le serveur de stockage, le calcul est exécuté. Tout cela fonctionne. Cependant, lors de la première utilisation de l'application, les identifiants réseau demandé à l'utilisateur. j'ai alors rajouté une recherche dans les lignes affichées par l'application, et déclenché une nouvelle form pour demander le mot de passe de l'utilisateur. Et c est la que le bas blesse, tant que mon sub ( click sur le boutton submit) n'est pas terminé, rien d'autre ne s'exécute. Dans un premier temps, j'ai voulu intégrer une console à ma form mais ca dépasse mes compétences. Je me retrouve donc bloqué.
    Je souhaiterais donc savoir comment faire pour que mes actions qui se trouvent dans le sub 'click submit button' soient traitées avant que ce dernier ne se termine.
    N'étant pas sur d'être très clair, je mets mon code, personne ne rigole svp j'ai commencé mercredi dernier


    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
    Imports System.Runtime.InteropServices
     
    Public Class Form1
        Dim abaqus_exec As String = ""
        Dim path As String = ""
        Dim DriveMap As String = "z:"
        Dim objNet, objFSO As Object
        Dim data_path As String = "\\sv0117\data\abaqus"
        Dim i As Integer = 0
        Dim job_folder As String
        Dim proc As New System.Diagnostics.Process()
        Dim loginform As New LoginForm1()
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            label_user.Text = "USER : " & System.Environment.UserDomainName & "\" & System.Environment.UserName
            Label_os.Text = "OS : " & System.Environment.OSVersion.VersionString
            label_computer.Text = "COMPUTER : " & System.Environment.MachineName.ToString
     
        End Sub
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_input.Click
            TextBox1.Text = ""
            OpenFileDialog1.ShowDialog()
            If OpenFileDialog1.FileName = "" Then
                Exit Sub
            End If
            If Not (New System.IO.FileInfo(OpenFileDialog1.FileName).Extension) = ".inp" Then
                Output("reset")
                Output("Only .inp files are supported as input file")
                TextBox1.Text = ""
                Exit Sub
            End If
            TextBox1.Text = OpenFileDialog1.FileName
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_submit.Click
            If check_user_input() = False Then
                Exit Sub
            Else
                Output("reset")
                define_abaqus()
                UAC()
                map()
                create_job_folder()
                move_file_to_server()
                submit_job()
            End If
        End Sub
     
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_cancel.Click
            End
        End Sub
     
        Sub Output(ByVal output_string)
            If output_string = "reset" Then
                output_console.Text = ""
                Exit Sub
            End If
            output_console.Text = output_console.Text & "#  " & output_string & vbCrLf
        End Sub
     
        Function check_user_input()
            If (FileIO.FileSystem.FileExists(TextBox1.Text) And ComboBox_version.Items.Contains(ComboBox_version.Text) And ComboBox_cores.Items.Contains(ComboBox_cores.Text)) Then
                Return True
                Exit Function
            Else
                Output("reset")
                If Not FileIO.FileSystem.FileExists(TextBox1.Text) Then
                    If TextBox1.Text = "" Then
                        Output("You must specify an input file")
                    Else
                        Output("File does not exist : " & TextBox1.Text)
                    End If
                End If
                If Not ComboBox_version.Items.Contains(ComboBox_version.Text) Then
                    If ComboBox_version.Text = "" Then
                        Output("You must specify an ABAQUS version")
                    Else : Output("Specified version not suported : " & ComboBox_version.Text)
                    End If
                End If
                If Not ComboBox_cores.Items.Contains(ComboBox_cores.Text) Then
                    If ComboBox_cores.Text = "" Then
                        Output("You must specify a number of core")
                    Else
                        Output("Specified cores number not supported : " & ComboBox_cores.Text)
                    End If
                End If
            End If
            Return False
        End Function
     
        Sub define_abaqus()
            '==================================================================================================
            'Defining the abaqus exec depending on version.
            '==================================================================================================
            Select Case System.Environment.OSVersion.Version.Build.ToString
                Case "3790"
                    Output("x64 OS detected, will use x64 ABAQUS version")
                    abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
                    path = "\\sv0117\Abaqus"
                Case "2600"
                    Output("x32 OS detected, will use x32 ABAQUS version")
                    abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
                    path = "\\sv0117\Abaqus_x32"
                Case Else
                    Output("Unknow OS bit code (" & System.Environment.OSVersion.Version.Build.ToString & "), will assume 32 bit version")
                    abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
                    path = "\\sv0117\Abaqus_x32"
            End Select
        End Sub
     
        Sub UAC()
            '==================================================================================================
            'user access control
            '==================================================================================================
            If Not IO.File.Exists(path & abaqus_exec) Then
                Output("server access failed ...")
                Output("The most common reason is because you're not allowed to use the compute cluster.")
                Output("Contact XXXXXX to request access to the compute cluster.")
                Exit Sub
            Else
                Output("Abaqus " & ComboBox_version.Text & " detected and operationnal")
            End If
        End Sub
     
        Sub map()
            '==================================================================================================
            'Mapping drive z: for ABAQUS
            '==================================================================================================
            objFSO = CreateObject("Scripting.FileSystemObject")
            objNet = CreateObject("Wscript.Network")
            If IO.File.Exists(DriveMap & "\" & abaqus_exec) Then
                Output("mapping on " & DriveMap & "already correct")
            ElseIf objFSO.DriveExists(DriveMap) Then
                Output(DriveMap & " map not mounted for ABAQUS use, will unmap and remap. If operation fails, remove " & DriveMap & " map manually.")
                objNet.RemoveNetworkDrive(DriveMap, True, True)
                objNet.MapNetworkDrive(DriveMap, path, True)
            Else
                Output("mapping z:")
                objNet.MapNetworkDrive(DriveMap, path, True)
            End If
            '==================================================================================================
            'Mapping drive y: for data transfert
            '==================================================================================================
            If IO.Directory.Exists(data_path & "\" & Environment.UserName) Then
                Output("found ... user directory on headnode")
                If objFSO.DriveExists("y:") Then objNet.RemoveNetworkDrive("y:", True, True)
                Output("mapping y:")
                objNet.MapNetworkDrive("y:", data_path & "\" & Environment.UserName, True)
            Else
                Output("user directory on headnode not found, will create")
                IO.Directory.CreateDirectory(data_path & "\" & Environment.UserName)
                If objFSO.DriveExists("y:") Then objNet.RemoveNetworkDrive("y:", True, True)
                Output("mapping y:")
                objNet.MapNetworkDrive("y:", data_path & "\" & Environment.UserName, True)
            End If
        End Sub
     
        Sub create_job_folder()
            '==================================================================================================
            'creating job folder
            '==================================================================================================
            If IO.Directory.Exists("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1))) Then
                Do Until Not (IO.Directory.Exists("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i))
                    i = i + 1
                Loop
                IO.Directory.CreateDirectory("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i)
                job_folder = "y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i
                Output("creating job folder " & job_folder)
            Else
                IO.Directory.CreateDirectory("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)))
                job_folder = "y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1))
                Output("creating job folder " & job_folder)
            End If
            i = 0
        End Sub
     
        Sub move_file_to_server()
            '==================================================================================================
            'moving file to server
            '==================================================================================================
            Output("moving " & TextBox1.Text)
            Output("to " & job_folder & "\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name))
            IO.File.Copy(TextBox1.Text, job_folder & "\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name))
        End Sub
     
        Sub submit_job()
            '==================================================================================================
            'submiting job
            '==================================================================================================
     
            Output("================================STARTING ABAQUS================================")
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.RedirectStandardOutput = True
            proc.StartInfo.WorkingDirectory = job_folder
            proc.StartInfo.FileName = path & abaqus_exec
            proc.StartInfo.Arguments = " -j " & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & " -cpus " & ComboBox_cores.Text
            proc.Start()
     
            Dim out_lines As String = ""
            While Not proc.StandardOutput.EndOfStream
                out_lines = proc.StandardOutput.ReadLine.ToString
                Output(out_lines)
                If Not IsNothing(out_lines) Then
                    If Not InStr(out_lines, "Enter the password for") = 0 Then
                        LoginForm1.ShowDialog()
                        sendkey(LoginForm1.PasswordTextBox.Text)
                        sendkey("{Enter}")
                        sendkey("y")
                        sendkey("{Enter}")
                    End If
                End If
            End While
            proc.WaitForExit()
            proc.Close()
            TextBox1.Text = ""
        End Sub
     
        Sub sendkey(ByVal my_key)
            proc.WaitForInputIdle(2000)
            System.Windows.Forms.SendKeys.SendWait("""" & my_key & """")
        End Sub
     
    End Class

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 2
    Par défaut
    En relisant, je me rend compte que c'est pas trop digeste ce que j'ai posté. Je vais essayé de le résumer :

    Voila le code suivant est exécuté lors d'un clic sur un bouton de ma form principale. Mon problème vient du fait que lorsque le programme s'exécute (proc.Start()) aucune interaction n'est possible avec ce même programme tant que ce dernier ne se termine pas. Ce dernier pouvant demander des identifiants, j'ai besoin de pouvoir ouvrir une nouvelle form (LoginForm1.Show()) qui réceptionne le mot de passe tapé par l'utilisateur et le renvoie (System.Windows.Forms.SendKeys.SendWait).

    J'espère que c est plus clair comme ca.

    Merci

    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
    Sub submit_job()
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.RedirectStandardOutput = True
            proc.StartInfo.WorkingDirectory = job_folder
            proc.StartInfo.FileName = "z:" & abaqus_exec
            proc.StartInfo.Arguments = " -j " & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & " -cpus " & ComboBox_cores.Text
            Output(proc.StartInfo.FileName & " " & proc.StartInfo.Arguments)
            proc.Start()
     
            While Not proc.StandardOutput.EndOfStream
                out_lines = proc.StandardOutput.ReadLine.ToString
                Output(out_lines)
                If Not IsNothing(out_lines) Then
                    If Not InStr(out_lines, "Enter the password for") = 0 Then
                        LoginForm1.Show()
                        System.Windows.Forms.SendKeys.SendWait(LoginForm1.PasswordTextBox.Text)
                        wait(2000)
                        System.Windows.Forms.SendKeys.SendWait("{Enter}")
                        wait(2000)
                        System.Windows.Forms.SendKeys.SendWait("y")
                        wait(2000)
                        System.Windows.Forms.SendKeys.SendWait("{Enter}")
                        Output("reset")
                    End If
                End If
            End While
            proc.WaitForExit()
            proc.Close()
            TextBox1.Text = ""
        End Sub

Discussions similaires

  1. Réponses: 7
    Dernier message: 12/04/2010, 13h26
  2. Réponses: 10
    Dernier message: 28/03/2010, 12h30
  3. [PHP-JS] Envoi de données sur une même page...
    Par dudux dans le forum Langage
    Réponses: 8
    Dernier message: 14/09/2005, 13h51
  4. [Debutant(e)]Execution d'un programme externe
    Par saidi_chahrat dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 26/08/2004, 11h35
  5. [debutant]envoie de données
    Par miloux32 dans le forum XML/XSL et SOAP
    Réponses: 4
    Dernier message: 14/08/2003, 10h24

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