当前位置:网站首页>Bat 使用细节2
Bat 使用细节2
2022-06-30 06:27:00 【警醒与鞭策】
/
c# 调用cmd.exe 调用 x.bat
I've been trying all day to start process which would run the following code:
C:\bin\ant.bat -f=C:\build.xml -DinputFile=C:\Desktop\Book1.xml -DstartDate=2018-06-20 -DxslFile=ProcessingDate -DoutputFile=fff and it works completely fine in cmd. What I have tried: this is my last code in C# which I really hoped would work, but however it doesn't:
public void run() {
string antFile = @"C:\ant.bat";
string build = @"C:\build.xml";
string inputFile = @"C:\Book1.xml";
string startDate = "2018-05-23";
string outputFile = "ff";
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c" + @"C:bin\ant.bat -f=C:\build.xml -DinputFile=C:\Desktop\Book1.xml -DstartDate=2018-06-20 -DxslFile=ProcessingDate -DoutputFile=test0.xsl");
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
ProcessStartInfo procStartInfo2 = new ProcessStartInfo("cmd.exe", "/c" + antFile + "-f=" + build + "-DinputFile=" + inputFile + "-DstartDate=" + startDate + "-DxslFile=" + startDate + "-DoutputFile=" + outputFile);
Process proc2 = new Process();
proc2.StartInfo = procStartInfo2;
proc2.Start();
}2 solutions
1、Your assembled command line looks like this:
cmd.exe /cC:\ant.bat-f=C:\build.xml-DinputFile=C:\Book1.xml-DstartDate=2018-05-23-dXslFile=2018-05-23-DoutputFile=ff Just concatenating strings together does not automatically put spaces in the appropriate places for you. You have to account for that yourself. Also, it greatly helps debugging if you put the strings into variables instead of directly assembling them as an argument in the function call:
string arguments=$"/c {antFile} -f={build} -DinputFile={inputFile} -DstartDate={startDate} -DxslFile={startDate} -DoutputFile={outputFile}";
ProcessStartInfo procStartInfo2 = new ProcessStartInfo("cmd.exe", arguments);2、
public static void RunCmd(string executeString)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo(executeString);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.UseShellExecute = false;
Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == -1)
throw new Exception(process.StandardOutput.ReadToEnd());
}///
Let’s imagine a simple app that will allow the user to change its resolution and window mode through the command line. For this example to work, we prepared a CommandLineController script that we attach to any object on the scene.
using System;
using UnityEngine;
public class CommandLineController : MonoBehaviour
{
#region MEMBERS
private const string windowModeArg = "isWindowedMode=";
private const string resolutionWidthArg = "width=";
private const string resolutionHeightArg = "height=";
[SerializeField]
private int defaultWidth = 1920; [SerializeField]
private int defaultHeight = 1080;
#endregion
#region PROPERTIES
public int DefaultHeight {
get { return defaultHeight; }
}
public int DefaultWidth {
get { return defaultWidth; }
}
#endregion
#region FUNCTIONS
void Start()
{
ParseCommandLineArguments();
}
private void ParseCommandLineArguments()
{
string[] args = System.Environment.GetCommandLineArgs();
int screenWidth = DefaultWidth;
int screenHeight = DefaultHeight;
bool isWindowsMode = false;
string argumentString; for (int i = 0; i < args.Length; i++)
{
argumentString = "";
if (args[i].StartsWith(windowModeArg) == true)
{
argumentString = args[i].Replace(windowModeArg, "");
Boolean.TryParse(argumentString, out isWindowsMode)
}
else if (args[i].StartsWith(resolutionWidthArg) == true)
{
argumentString = args[i].Replace(resolutionWidthArg, "");
Int32.TryParse(argumentString, out screenWidth);
}
else if (args[i].StartsWith(resolutionHeightArg) == true)
{
argumentString = args[i].Replace(resolutionHeightArg, "");
Int32.TryParse(argumentString, out screenHeight);
}
}
Screen.SetResolution(screenWidth, screenHeight, isWindowsMode == false);
}
#endregion
#region CLASS_ENUMS
#endregion
}Upon start, the script checks for any command-line arguments. If it finds any arguments fitting the width, height or is windowed mode parameters, it tries to parse them and then change the screen resolution and FullScreen mode accordingly.
Because Unity stores the last set resolution for the player in the registry, we declared two fields that store the default width and height for the script to use.

So, if our default resolution is 1920×1080 and the app is in FullScreen mode, launching it with the following parameters:
C:\Users\<user name>\Desktop\CommandLine\CommandLineExample.exe width=640 height=480 isWindowedMode=true
will cause the app to change the resolution to 640×480 and display in a window.
As we can see, command line parameters can be used to customize any aspect of the app upon launch. By removing the need for preparing multiple different builds for different parties like testers or clients, this very handy feature saves us time and makes it easier to manage build configurations.
From resolution changes and developer-mode options to more robust server configurations – accessing the parameters is very simple and can be easily integrated into an existing app.
/
/
边栏推荐
- A small template (an abstract class, a complete process is written in a method, the uncertain part is written in the abstract method, and then the subclass inherits the abstract class, and the subclas
- Image processing 7- image enhancement
- To: k210 realizes face recognition (code interpretation attached)
- 股票在网上开户安全吗?在网上能不能开户炒股呢?
- Using C language pure for loop to implement ilovey
- ES6扩展运算符(...)
- 关注这场直播,了解能源行业双碳目标实现路径
- 深度学习---三好学生各成绩所占权重问题(3)
- Application of redis client list in practice
- Data read / write: realize data read / write function based on C # script in unity
猜你喜欢

Common NPM install errors

Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold

Unclear about glide loading picture

IO streams (common streams)

图片。。。。。

Use and principle of completionservice (source code analysis)

Feisheng: Based on the Chinese word breaker ik-2 ways to build custom hot word separators Showcase & pit arrangement Showtime

Gazebo installation, uninstall and upgrade

神经网络入门

Rhcsa day 1
随机推荐
Spin official tutorial
IO stream (file class introduction)
Develop stylelint rules from zero (plug-ins)
Learn fpga---ram IP core and key parameters from the bottom structure
Inner member of class 5: inner class
Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
46. full arrangement -dfs double hundred code
Common NPM install errors
requests. The difference between session () sending requests and using requests to send requests directly
一个完整的性能测试流程
我做功能测试这么多年的心得
多线程进阶篇
不忘初心,能偷懒就偷懒:C#操作Word文件
01. regular expression overview
Usage of case, casez and casex statements in Verilog
Zibll子比主题V6.4.1wordpress 开心版源码下载_破解原版/直接使用/无需教程
Cocos studio3.1 installation package win
CompletableFuture从了解到精通,你想知道的这里都有
Golang's handwritten Web Framework
Vscode configuration proxy