C# to call external program via cmd.exe and pass arguments

ds1718

Client
Регистрация
25.11.2011
Сообщения
33
Благодарностей
4
Баллы
0
I am trying to grab an image from my network and resize and rename with image magic.

When I use the following commands it works.


convert.exe -resize 588x420 \\ut02\pics-dotnet\images\DealerCMO\Cash_For_Cars\Cash_For_Cars\Images\cl_upload\YV1AS982491100676\1.jpg "X:\ZCL_Poster\Production\CA-SFBay\ctd-CA-SFBay-eby-1\Images\expl blac padd fourt 5864.jpg"

this tells image magic to convert with resize the file from \\ut02 to X: ( local project directory) image folder and new name.
this works perfect when pasted to cmd window. Requirres the " around last file" as it can contain spaces.

Now the C# I am using is as follows

string strCmdText= "/c convert.exe -resize" 600x450 \\\\ut02\\pics-dotnet\\images\\DealerCMO\\Cash_For_Cars\\Cash_For_Cars\\Images\\cl_upload\\YV1AS982491100676\\1.jpg \"X:\\ZCL_Poster\\Production\\CA-SFBay\\ctd-CA-SFBay-eby-1\\Images\\expl blac padd fourt 5864.jpg\"";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

this works fine. and makes the same image from the C# block.

the Quotes around the second file have to be escaped, and so to all the \

the problem is now turning them into variables

anytime I try to make the 2 paths into a variable it fails.

I think the issues in the last file argument being in quotes.

I have tried this, and it fails too

string localpath = "project.Variables['Image_LocalFullPath'].Value";
string size = "project.Variables['Image_Resize'].Value";
string origpath = "project.Variables['Image_OrigPath'].Value";
string strCmdText= "/c convert.exe -resize" + size + origpath + \"localpath\"";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

It apears that this is no longer interpretted as a variable
\"localpath\"

but it has to have quotes around it to the cmd

also don't know if I need the files to be escaped or not inside the variable, tried it both ways and both failed

Please help
 

ds1718

Client
Регистрация
25.11.2011
Сообщения
33
Благодарностей
4
Баллы
0
Got it...

string source = @"" + project.Variables["Image_OrigPath"].Value + "";
string destination = @"" + project.Variables["Image_LocalFullPath"].Value + "";
string size = project.Variables["Image_Resize"].Value;

System.Diagnostics.Process.Start("C:\\IM\\convert.exe", "-resize " + size + " " + source + " \"" + destination + "\"");
 

waleedijaz321

Новичок
Регистрация
27.04.2016
Сообщения
1
Благодарностей
0
Баллы
1
also don't know if I need the files to be escaped or not inside the variable, tried it both ways and both failed??



waleeed
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 714
Баллы
113
You dont need to escape data if it's stored in variable
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)