question

SimonScott-1980 avatar image
0 Votes"
SimonScott-1980 asked SimonScott-1980 commented

Opening CMD Line

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

dotnet-visual-basic
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This doesn't look like Small Basic. So you should remove the small-basic-general tag and look for a more fitting tag.

0 Votes 0 ·

Apologies amended

0 Votes 0 ·

Ok thank you, i will create another question.

Kind regards
Simon

0 Votes 0 ·

1 Answer

XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered SimonScott-1980 commented

Hi @SimonScott-1980 ,

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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Xingyu,

Thank you for your answer, sorry for not replying sooner, i've been on another project.

What you have given works as it should but i'm stuck on the last piece of this little project.

I'm basically trying to read a text file which contains a line of text (in this instance it says (UTC-03:00) City of Buenos Aires | Argentina Standard Time) for setting a timezone on a PC. Here is my code

Dim sString As String = Nothing
Using sr As New StreamReader("c:\temp\test.ini")
sString = sr.ReadToEnd()
End Using
Dim sSubString = sString.Substring(sString.LastIndexOf(" | ") + 1)
' MsgBox(sSubString)

     Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s " + sSubString))
     Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
     proc.StartInfo = procStartInfo
     proc.Start()

This is what happens when i run the program...

'Argentina' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Admin\OneDrive\Projects\Timezone\TimeZone\TimeZone\bin\Debug>

Sorry i'm only a beginner at programming. Can you help at all?

Thanks
Simon

0 Votes 0 ·

Hi @SimonScott-1980 ,
Thanks for your feedback.
I suggest you create a new question in the forum. so that more people will participate in the thread, and we will provide our help and suggestions there.

0 Votes 0 ·