Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SharePoint > SharePoint Development
| Search | Today's Posts | Mark Forums Read
SharePoint Development Programming and development for SharePoint Portal Server and Windows SharePoint Services
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SharePoint Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 17th, 2007, 12:24 PM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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);
                }
        }




Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell command under Windows Vista mileski Access VBA 0 April 16th, 2007 10:17 AM
how to alter shell command to direct where window dgr7 Beginning VB 6 4 March 16th, 2007 02:00 PM
Shell Command doesn't respond in W2K machines kan_lenny Pro VB.NET 2002/2003 0 September 13th, 2006 07:36 PM
Shell command execution error toshesh VB Databases Basics 3 January 7th, 2006 03:17 AM
Shell command refusing to work underscore10304 Access VBA 4 October 20th, 2004 02:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.