I have a console file, which takes 6 arguments
To run this exe, I create one batch file,
Now, I need to send this parameter to the batch file from my one Windows application. This is the code:
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();
But its not working. I tried to change my Batch file like,
@echo off %1 %2 %3 %4 %5 %6 %7
@echo off
but that didn't work either.
Error Image:
Arguments
should be seperated
by space
.
Method 1:
proc.StartInfo.Arguments =consolepath+" "+Pc+" "+database+" "+UserName+" "+Password+" "+"F"+" "+bacPath;
Method 2: using String.Format()
proc.StartInfo.Arguments =String.Format("{0} {1} {2} {3} {4} {5} {6}",consolepath,Pc,database,UserName,Password,"F",bacPath);
Solution 2: you should not hardcode the parameter values in batch file
Try This: change the Batch file as below
%1 %2 %3 %4 %5 %6 %7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With