Link to home
Start Free TrialLog in
Avatar of turn123
turn123Flag for United States of America

asked on

Process.Start "Access is denied" exception

When I run this code it will start the cmd process twice then the third time it gives an unhandled exception "Access is denied".  What is going on and how do I fix it?
string pram = "";
            for (int i = 0; i < 4000; ++i)
            {
                pram += 'i';
                if(pram.Length > 2050)
                Process.Start("cmd.exe", pram);
            }

Open in new window

Avatar of turn123
turn123
Flag of United States of America image

ASKER

Using VS 2008 to compile and OS is XP Pro if it makes any difference.
CMD has a maxium size for a "command line" at about 8k...   What are you trying to do?
Avatar of turn123

ASKER

I'm passing an XML file to another program as a command line argument to be parsed and printed.

Basically I'm trying to get the same functionality as an existing Perl script that calls it with the system command.

Is there another way I should be doing this?
system "PrintInvoiceVer.exe $xml";

Open in new window

Pardon me, but what the heck does that have to do with the sample you posted.... I'm very confused.
Try this:   "cmd /c PrintInvoiceVer.exe " & xmlfilenamevariable
Avatar of turn123

ASKER

The example I posted was an a test case showing where the problem was occurring.  The second example is was what the current program I am replacing is doing that works.  It seems that both should work.

Anyway when I try your suggestion I'm getting a compile error.

"Operator '&' cannot be applied to operands of type 'string' and 'string'"
Ooops, try "+"
Avatar of turn123

ASKER

Now it is throwing an unhandled exception "The system cannot find the file specified"
string pram = "";
            for (int i = 0; i < 4000; ++i)
            {
                pram += 'i';
                if (pram.Length > 2050)
                    Process.Start("cmd /c PrintInvoiceVer.exe " + pram);
            }

Open in new window

Because there is no file called iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Again, that's a very strange example.    I don't understand what that example has to do with anything... are you testing the length of the items you can put in a command line?
Avatar of turn123

ASKER

There is no file called


<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<InvoiceQueryRs statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<InvoiceRet>
<TxnID>39C6BB-1220637230</TxnID>
<TimeCreated>2008-09-05T13:53:50-05:00</TimeCreated>


either.  This is part of the parameter I'm trying to pass to a command line program so that it can process it.  It doesn't seem to matter what I pass.  Once it exceeds a certain length I get the access is denied error when using process.start.

When I try using the example you gave it says it can't find the file.
Wow.... Now, I know I'm totally lost.  
Let's start from the very beginning and have you describe what the heck you're trying to do.  Please don't  give us an example of what you've tried so far... that's obvioulsy not helping much.   Instead concentrate on a bettter description of the problem
Avatar of turn123

ASKER

Ok I have a program that excepts a command line argument of an XML file.  I am trying to start this program and pass it the XML file as an argument.
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dang.... I missed a word
The name of the file should NOT make the command line too long.... it'd be something like this:
Avatar of turn123

ASKER

That's basically what I'm doing now.  I would prefer not to have to write a file if that is possible to do.  I'm thinking there should be a way to do it without writing a file as I can do it in Perl without having to write a file.