Running a shell command in sharepoint.
Im trying to invoke a java barcode generator on one of my pages. If
run within an asp.net page it runs perfectly, if I "echo" the command
line generated and run it within a command shell, it runs perfectly,
if I run this within sharepoint I get zilch in the directory and no
error message. Ive tracked it down to the process execution, which
returns True. Can someone please shed some light on my code or give
me some examples on how YOU did it? Thanks in advance.
Some of the code :
protected void Genbarcode(string CEPNumber)
{
string WorkingDirectory;
WorkingDirectory = "C:\\";
string strBarcodeDirectory;
strBarcodeDirectory = "[barcodeDIR]";
//strBarcodeDirectory = "C:\\Program Files\\Common Files\\Microsoft
Shared\\web server extensions\\12\\TEMPLATE\\IMAGES\\SS\\Barcodes\\";
string strJavaLoc;
strJavaLoc = "C:\\Program Files\\Java\\jre1.6.0_02\\bin\\java.exe";
string strBarcodeLoc;
strBarcodeLoc = "-cp " + WorkingDirectory + "barcode4j-1.0\\build\barcode4j.jar;" + WorkingDirectory + "barcode4j-1.0\\lib\\avalon-
framework-4.1.5.jar;" + WorkingDirectory + "barcode4j-1.0\\lib\commons-cli-1.0.jar org.krysalis.barcode4j.cli.Main -o \"" +
strBarcodeDirectory + CEPNumber + ".png\" -f png --bw -d 600 -s
code128 \"" + CEPNumber + "\"";
if (!FileExists(strBarcodeDirectory, CEPNumber + ".png"))
{
try
{
Run_Shell_Command(strJavaLoc, strBarcodeLoc);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
protected void Run_Shell_Command(string FileName, string Arguments)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = FileName;
if (Arguments.Length > 0)
{
proc.StartInfo.Arguments = Arguments;
}
try
{
Response.Write(proc.Start());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected bool FileExists(string strDirectory, string strFilename)
{
try
{
string fileLoc = strDirectory + strFilename;
FileInfo fi = new FileInfo(fileLoc);
return (fi.Exists);
}
catch (Exception ex)
{
Response.Write(ex.Message);
return (true);
}
}
|