我试图为我制作的一个需要制作和启动.bat文件的游戏重新创建启动器的源代码。当需要将附加的行打包到.bat中时,我发现了这个错误。我已经研究过了,甚至彻底研究过。我之所以问自己,是因为我遇到的答案都不符合我的情况。批量设置变量,回显一些文本,然后启动游戏。这是代码,谢谢你帮我。如果你需要,我会添加更多信息,我会尽我所能提供帮助。
sb.AppendLine("@echo off")
sb.AppendLine("set ttiUsername=" + username)
sb.AppendLine("set ttiPassword=password")
sb.AppendLine("set TTI_GAMESERVER=10.0.0.77")
sb.AppendLine("set TTI_PORT=7198")
sb.AppendLine("set /P PPYTHON_PATH=<PPYTHON_PATH")
sb.AppendLine("echo ===============================")
sb.AppendLine("echo Welcome to Toontown Rebuilt, %ttiUsername%!")
sb.AppendLine("echo You are connecting to server %TTI_GAMESERVER%!")
sb.AppendLine("echo The server port is %TTI_PORT%")
sb.AppendLine("echo ===============================")
sb.AppendLine("%PPYTHON_PATH% -m toontown.toonbase.ToontownStart")
Dim File As New System.IO.StreamWriter
File.WriteLine(sb.ToString())
Process.Start("C:Toontown Rebuilt SourceToontownRebuiltLauncher.bat")
System.IO.StreamWriter构造函数需要一个参数。连续的Write
将在其中转储字符串内容的文件或已创建的流的名称。您缺少该参数
但是这里还有其他问题需要改变
Using File = New System.IO.StreamWriter("C:Toontown Rebuilt SourceToontownRebuiltLauncher.bat")
File.WriteLine(sb.ToString())
End Using
Using语句中的封装确保了流的正确关闭和处理
另一种有用的方法是File.WriteAllText
Dim file = "C:Toontown Rebuilt SourceToontownRebuiltLauncher.bat"
File.WriteAllText(file, sb.ToString())
嗨,我使用您的代码并修复您的bug以启动bat。
这是我在VB.NET中的代码:
Dim sb As New StringBuilder
Dim username As String
username = "test"
sb.AppendLine("@echo off")
sb.AppendLine("set ttiUsername=" + username)
sb.AppendLine("set ttiPassword=password")
sb.AppendLine("set TTI_GAMESERVER=10.0.0.77")
sb.AppendLine("set TTI_PORT=7198")
sb.AppendLine("set /P PPYTHON_PATH=<PPYTHON_PATH")
sb.AppendLine("echo ===============================")
sb.AppendLine("echo Welcome to Toontown Rebuilt, %ttiUsername%!")
sb.AppendLine("echo You are connecting to server %TTI_GAMESERVER%!")
sb.AppendLine("echo The server port is %TTI_PORT%")
sb.AppendLine("echo ===============================")
sb.AppendLine("%PPYTHON_PATH% -m toontown.toonbase.ToontownStart")
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("C:tmpLauncher.bat", True)
file.WriteLine(sb.ToString)
file.Close()
Process.Start("C:tmpLauncher.bat")