algorithmic modeling for Rhino
I everyone,
I am trying to write commands into a .bat file and then run it inside a VB component. To help solve the issue I use the following simple code:
Private Sub RunScript(ByVal x As Boolean)
Dim content As String
Dim path As String
content = "@ECHO" & vbCr & _
"ECHO Test" & vbCr & _
"PAUSE"
path = "C:\Users\test.bat"
File.WriteAllText(path, content)
If x Then Diagnostics.Process.Start(path)
End Sub
It works fine for writing this on .bat file:
@ECHO
ECHO Test
PAUSE
But when trying to run the .bat, the cmd window opens and closes immediately without running commands. Does anybody has an idea of the issue?
Thanks,
Tags:
No idea. Do note that vbCr is not a good thing to use. It only encodes the Carriage Return and omits the LineFeed. It's better to use Environment.NewLine, which works no matter what the local conventions are.
Does the bat file work if you double click it in Explorer?
--
David Rutten
david@mcneel.com
Okay I changed from "vbCr" to "vbNewline" to do the carriage return and line feed and it works fine!
Without that, the bat file didn' lauched in explorer neither.
Thanks for your advice.
I didn't say vbNewLine. Use Environment.NewLine as it's the same between VB and C# and it's platform independent.
--
David Rutten
david@mcneel.com
Have you tried the /K approach of launching the file?
cmd /k C:\Users\test.bat
I didn't thought to use this, when using "vbCr" instead of "vbNewline" it clearly shows that no code is running in cmd which I caught a sight of when the window open and close immediately.
Thanks for the tips, it works fine since I replaced "vbCr" by vbNewline.
Welcome to
Grasshopper
© 2025 Created by Scott Davidson.
Powered by