当前位置:网站首页>Bat usage details 2
Bat usage details 2
2022-06-30 06:32:00 【Vigilance and encouragement】
/
c# call cmd.exe call 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.
/
/
边栏推荐
- VIM view file code
- 46. full arrangement -dfs double hundred code
- Base64详解:玩转图片Base64编码
- 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
- 46. 全排列-dfs双百代码
- Gazebo model modification
- 01. 正则表达式概述
- 从底层结构开始学习FPGA----RAM IP核及关键参数介绍
- [wechat applet: single or multiple styles, background color, rounded corners]
- ini解析学习文档
猜你喜欢

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

Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required

Dynamic routing job

RSA and AES

01. 正则表达式概述

IP TCP UDP network encryption suite format

Connect to remote server

New project folder based on PIO plug-in in vscode -- Interpretation

1.7 - CPU的性能指标

1.3 - 码制
随机推荐
Golang's handwritten Web Framework
Win10 /11 开热点无法上网问题
Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
Common NPM install errors
Rotate dimension tool rolabelimg
Summary of 2 billion redis data migration
Installing googleplay environment on Huawei mobile phones
Go pack and unpack
Unable to access the Internet at win10 /11 hotspot
Thread safe solutions, communication between threads (classic examples of producers and consumers)
HuaWei满级大牛首次分享出这份598页网络协议全彩手册
List in set (2)
Unable to read file for extraction: gdx64. dll
JS prototype chain object function relationship
Docker is equipped with the latest MySQL image
Cocos studio3.1 installation package win
Detailed description of methods in the interface
As function memo
01. 正则表达式概述
583. deleting two strings - Dynamic Planning