Share via

Opening CMD Line

Simon Scott 306 Reputation points
2020-12-01T13:14:53.44+00:00

Good afternoon,

@Castorix31 has kindly helped me with one part of my project, shown below and i just require assistance for the next easy bit.

Dim sString As String = Nothing
Using sr As New StreamReader("E:\Testxxx.txt")
sString = sr.ReadToEnd()
End Using
Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1)
Console.WriteLine(sSubString)

How do i send the text stored in sSubString to a CMD line? I need the CMD line to open and run with that text and stay open (so i can check its run ok).

I have looked online but there are multiple examples but can't quite fathom out which should work for me.

Kind regards
Simon

Developer technologies | VB

Answer accepted by question author

Xingyu Zhao-MSFT 5,381 Reputation points
2020-12-02T03:30:39.203+00:00

Hi @Simon Scott ,

I need the CMD line to open and run with that text and stay open

I make a test on my side and here's the code you can refer to.

    Public Sub ExecuteCommand(ByVal command As Object)  
        Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & command)  
        Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()  
        proc.StartInfo = procStartInfo  
        proc.Start()  
    End Sub  

    '...  
    ExecuteCommand(sSubString)  

Hope it could be helpful.

Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.