我有一个控制台文件,它有6个参数

要运行此exe,我创建一个批处理文件,

现在,我需要从我的一个Windows应用程序将此参数发送到批处理文件.这是代码:
string consolepath = @"E:\SqlBackup_Programs\console-backup\Backup_Console_App";
string Pc = "VARUN-PC";
string database = "Smart_Tracker";
string UserName = "sa";
string Password = "admin@12";
string bacPath = @"D:\TEST";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = System.Configuration.ConfigurationManager.AppSettings["BATCH_FULLBACKUP"].ToString().Trim();
proc.StartInfo.Arguments = String.Format(consolepath,Pc,database,UserName,Password,"F",bacPath);
//set the rest of the process settings
proc.Start();
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我试图更改我的批处理文件,如,
@echo off%1%2%3%4%5%6%7
@echo关闭
但那也不起作用.
错误图片:
Arguments应seperated通过space.
方法1:
proc.StartInfo.Arguments =consolepath+" "+Pc+" "+database+" "+UserName+" "+Password+" "+"F"+" "+bacPath;
Run Code Online (Sandbox Code Playgroud)
方法2:使用String.Format()
proc.StartInfo.Arguments =String.Format("{0} {1} {2} {3} {4} {5} {6}",consolepath,Pc,database,UserName,Password,"F",bacPath);
Run Code Online (Sandbox Code Playgroud)
解决方案2: 您不应该在批处理文件中对参数值进行硬编码
试试这个:更改批处理文件,如下所示
%1 %2 %3 %4 %5 %6 %7
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19734 次 |
| 最近记录: |