1 Reply Latest reply on Aug 22, 2016 9:11 AM by Patrick.Cashman

    Attempting to login to a cvs server using VB.net System.Diagnostics.Process

    bem

      Hello There,

      I realize that this question is not specifically about Mentor tools however it is concerning our Mentor design environment.

      I am attempting to develop a VB studio 2015 application that needs to interface (use) the cvs.exe (from CVSNT) command, but first I need to login to the server. I searched and I cannot seem to find an solution.

      I can execute the command using the process class, and I see the first response from the command .....

      Logging in to :pserver:xxxxx@xxxxxxxx.com:2401:/opt/xxxxxx/xxxxxRep

      However I do not see the line prompt (which I think goes to errout)

      CVS password:

      I enter the password anyways but it just seems to hang.

      Any help on how to interact with a command that is asking for a password will be appreciated.

      Thanks

      Brian

      The code that I am attempting to use is....

       

      ----------------------------------------------------------------------------------------------

      ' Example From
      ' https://pradeep1210.wordpress.com/2010/02/04/launching-and-controlling-external-applications-from-vb-net-application/

      Public Class Form1
        
      Private WithEvents MyProcess As Process
        
      Private Delegate Sub AppendOutputTextDelegate(ByVal text As String)


        
      Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
      Me.AcceptButton = ExecuteButton
        MyProcess
      = New Process
        
      With MyProcess.StartInfo
        
      '.FileName = "CMD.EXE"
        
      .FileName = "C:\Program Files (x86)\cvsnt\cvs.exe"
        
      .Arguments = "login xxxxxxx"

        
      .UseShellExecute = False
        
      .CreateNoWindow = True
        
      .RedirectStandardInput = True
        
      .RedirectStandardOutput = True
        
      .RedirectStandardError = True
        
      End With
        MyProcess
      .Start()

        MyProcess
      .BeginErrorReadLine()
        MyProcess
      .BeginOutputReadLine()
        AppendOutputText
      ("Process Started at: " & MyProcess.StartTime.ToString)
        
      End Sub

        
      Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MyProcess
      .StandardInput.WriteLine("EXIT") 'send an EXIT command to the Command Prompt
        MyProcess
      .StandardInput.Flush()
        MyProcess
      .Close()
        
      End Sub

        
      Private Sub MyProcess_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.ErrorDataReceived
        System
      .Diagnostics.Debug.WriteLine("ERROR OUT: " & e.Data)
        AppendOutputText
      (vbCrLf & "Error: " & e.Data)
        
      End Sub

        
      Private Sub MyProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.OutputDataReceived
        System
      .Diagnostics.Debug.WriteLine("STD OUT: " & e.Data)
        AppendOutputText
      (vbCrLf & e.Data)
        
      End Sub

        
      Private Sub ExecuteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExecuteButton.Click
        MyProcess
      .StandardInput.WriteLine(InputTextBox.Text)
        MyProcess
      .StandardInput.Flush()
        InputTextBox
      .Text = ""
        
      End Sub

        
      Private Sub AppendOutputText(ByVal text As String)
        
      If OutputTextBox.InvokeRequired Then
        
      Dim myDelegate As New AppendOutputTextDelegate(AddressOf AppendOutputText)
        
      Me.Invoke(myDelegate, text)
        
      Else
        OutputTextBox
      .AppendText(text)
        
      End If
        
      End Sub
      End Class

        • 1. Re: Attempting to login to a cvs server using VB.net System.Diagnostics.Process
          Patrick.Cashman

          I don't know anything about cvs, but from a web search it appears to be able to be controlled by a command line interface.  The shell command is better suited to this kind of interaction where multiple commands may need to be issued in sequence.  The process command is a higher-level device which you can use to start an executable with arguments, but after the startup, issuing more arguments may not be possible. 

           

          I've used process.start to launch things like acrobat.exe on a particular pdf file. At that point, you don't have much control over what the process does because it's off and running on its own.  In the case of acrobat, there is an API which I use to continue interaction with the software and a file it has open. 

           

          But for straight up command line programs, shell is better. For example, here is a bit that starts and runs 7zip to compress a design directory:

           

          Sub zip_design()

                   Dim cmd As String

                   Dim exe_path, zip_exe As String

                   Dim zip_name, tmp As String

           

                    get_project_directory_path()    'gets current_prj_dir

                   exe_path = Application.StartupPath() & "\"

                    zip_exe = exe_path & "7za"        'I have the 7zip command line version executable with my application exe

                  

                   zip_name = current_prj_dir.Substring(0, current_prj_dir.Length - 1) & ".7z"

                  

                   'the following two lines are where the action happens

                   cmd = zip_exe & " a " & zip_name & " -r " & current_prj_dir & "*.*"

                   shell(cmd)

           

          End Sub

          The commands for cvs appear to be fairly well documented on the web.  I didn't look to see exactly how the password is sent, but from what I did see, it's definitely possible.  There are lots of other functions you can also do using the command line, so in that case the shell is definitely the way I'd approach it. 

          I also saw on the cvsnt wikipedia page that there's an API for it.  You might want to investigate that too.