Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start - Pass html code to exe as argument

I am using the code below to start a executable file from a windows service and I need to pass html code (stored in a variable) as an argument. I am escaping with double quotes but this is not working. What do I need to do in order to pass this correctly? Thanks in advance for any guidance that is offered.

Inside the service:

Process.Start(@"E:\Program Files\MyApp.exe", dr["rec"].ToString() +
                                  " \"" + subject + "\" \"" + htmlVar);

and then within MyApp.exe:

static void Main(string[] args)
{
    Program MyProg = new Program();
    MyProg.MyMeth(args[0].ToString(), args[1].ToString(), args[2].ToString());
}

The exe file is just a simple app that handles the sending of emails. dr["rec"].ToString() is the email address of the recipient. The variable "subject" will contain the subject of the email. The variable "htmlVar" could contain anything, divs, images, hyperlinks, etc.. and the html code could be quite lengthy. Should I not be trying to pass this much data as an argument? Thanks again for the help.

like image 681
user1017477 Avatar asked Dec 23 '22 04:12

user1017477


2 Answers

You may need to encode the following characters to make them passable in a command line argument:

  • Double quotes
  • Carriage returns
  • Line feeds
like image 71
LBushkin Avatar answered Jan 06 '23 09:01

LBushkin


Be careful not to pass too much on the command-line:

  • What is the command line length limit?

I think 2000+ characters is starting to get too long.

like image 37
Jared Updike Avatar answered Jan 06 '23 10:01

Jared Updike