.net ProcessStartInfo passing arguments as variables
Posted: 2011-10-11T10:01:21-07:00
I am trying to execute a bat file via a .Net console app, but I can tell that the bat file is not accepting the parameters even though I think I have the correct format in passing them.
What am I doing wrong?
Here is the method in the console app that I'm executing.
private static int ProcessBatFile(string ifldr, string ofldr, string iext, string oext, Int16 filewidth, Int16 fileheight, Int16 ctr)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = ConfigurationSettings.AppSettings.Get("BatProcessDir") + "imagemagick.bat";
psi.Arguments = "-ifldr=" + ifldr + " -ofldr=" + ofldr + " -iext=" + iext + " -oext=" + oext + " -iwid=" + filewidth + " -ihgt=" + fileheight;
psi.UseShellExecute = false;
Process process = new Process();
process.StartInfo = psi;
process.Start();
return ctr;
}
My psi properties look like below during debugging: ?psi
{System.Diagnostics.ProcessStartInfo}
Arguments: "-ifldr=C:\\Temp\\Images\\c000\\ -ofldr=C:\\Temp\\100_100_gif_0 -iext=jpg -oext=gif -iwid=100 -ihgt=100"
CreateNoWindow: false
Domain: ""
EnvironmentVariables: {System.Collections.Specialized.StringDictionaryWithComparer}
ErrorDialog: false
ErrorDialogParentHandle: 0x00000000
FileName: "C:\\Temp\\imagemagick.bat"
LoadUserProfile: false
Password: null
RedirectStandardError: false
RedirectStandardInput: false
RedirectStandardOutput: false
StandardErrorEncoding: null
StandardOutputEncoding: null
UserName: ""
UseShellExecute: false
Verb: ""
Verbs: {string[0x00000005]}
WindowStyle: Normal
WorkingDirectory: ""
Below, is the code in the bat file I'm trying to execute:
@echo on
del %ofldr%.*
cd %ifldr%
mogrify -path %ofldr% -resize %iwid%x%ihgt% -format %oext% *.%iext%
If I execute the below bat file with input directly typed into the DOS prompt, it works fine (see below):
Note: Typed in input folder name: C:\Temp\Images\c000\
Typed in output folder name: C:\Temp\100_100_gif_0
@echo off
echo Input folder of images you want to convert?
set /p ifldr=
echo.
echo Input file extension of images that you want to convert?
set /p iext=
echo.
echo Output folder where the new images will reside?
set /p ofldr=
echo.
echo Extension that you want the new images to be?
set /p oext=
echo.
echo Image width?
set /p iwid=
echo.
echo Image height?
set /p ihgt=
echo.
del %ofldr%.*
cd %ifldr%
mogrify -path %ofldr% -resize %iwid%x%ihgt% -format %oext% *.%iext%
echo Files converted
pause
Thanks a lot,
Bill....
What am I doing wrong?
Here is the method in the console app that I'm executing.
private static int ProcessBatFile(string ifldr, string ofldr, string iext, string oext, Int16 filewidth, Int16 fileheight, Int16 ctr)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = ConfigurationSettings.AppSettings.Get("BatProcessDir") + "imagemagick.bat";
psi.Arguments = "-ifldr=" + ifldr + " -ofldr=" + ofldr + " -iext=" + iext + " -oext=" + oext + " -iwid=" + filewidth + " -ihgt=" + fileheight;
psi.UseShellExecute = false;
Process process = new Process();
process.StartInfo = psi;
process.Start();
return ctr;
}
My psi properties look like below during debugging: ?psi
{System.Diagnostics.ProcessStartInfo}
Arguments: "-ifldr=C:\\Temp\\Images\\c000\\ -ofldr=C:\\Temp\\100_100_gif_0 -iext=jpg -oext=gif -iwid=100 -ihgt=100"
CreateNoWindow: false
Domain: ""
EnvironmentVariables: {System.Collections.Specialized.StringDictionaryWithComparer}
ErrorDialog: false
ErrorDialogParentHandle: 0x00000000
FileName: "C:\\Temp\\imagemagick.bat"
LoadUserProfile: false
Password: null
RedirectStandardError: false
RedirectStandardInput: false
RedirectStandardOutput: false
StandardErrorEncoding: null
StandardOutputEncoding: null
UserName: ""
UseShellExecute: false
Verb: ""
Verbs: {string[0x00000005]}
WindowStyle: Normal
WorkingDirectory: ""
Below, is the code in the bat file I'm trying to execute:
@echo on
del %ofldr%.*
cd %ifldr%
mogrify -path %ofldr% -resize %iwid%x%ihgt% -format %oext% *.%iext%
If I execute the below bat file with input directly typed into the DOS prompt, it works fine (see below):
Note: Typed in input folder name: C:\Temp\Images\c000\
Typed in output folder name: C:\Temp\100_100_gif_0
@echo off
echo Input folder of images you want to convert?
set /p ifldr=
echo.
echo Input file extension of images that you want to convert?
set /p iext=
echo.
echo Output folder where the new images will reside?
set /p ofldr=
echo.
echo Extension that you want the new images to be?
set /p oext=
echo.
echo Image width?
set /p iwid=
echo.
echo Image height?
set /p ihgt=
echo.
del %ofldr%.*
cd %ifldr%
mogrify -path %ofldr% -resize %iwid%x%ihgt% -format %oext% *.%iext%
echo Files converted
pause
Thanks a lot,
Bill....