Solved

Process.Start "Access is denied" exception

Posted on 2008-11-03
14
2,713 Views
Last Modified: 2008-12-10
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

0
Comment
Question by:turn123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 11

Author Comment

by:turn123
ID: 22868387
Using VS 2008 to compile and OS is XP Pro if it makes any difference.
0
 
LVL 41

Expert Comment

by:graye
ID: 22868675
CMD has a maxium size for a "command line" at about 8k...   What are you trying to do?
0
 
LVL 11

Author Comment

by:turn123
ID: 22869362
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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Expert Comment

by:graye
ID: 22870066
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
0
 
LVL 11

Author Comment

by:turn123
ID: 22885169
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'"
0
 
LVL 41

Expert Comment

by:graye
ID: 22887171
Ooops, try "+"
0
 
LVL 11

Author Comment

by:turn123
ID: 22887234
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

0
 
LVL 41

Expert Comment

by:graye
ID: 22889218
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?
0
 
LVL 11

Author Comment

by:turn123
ID: 22889247
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.
0
 
LVL 41

Expert Comment

by:graye
ID: 22891107
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
0
 
LVL 11

Author Comment

by:turn123
ID: 22894056
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.
0
 
LVL 41

Accepted Solution

by:
graye earned 250 total points
ID: 22894368
So, write the XML data to a file, and then use that file name as an argument when doing a Process.Start
"PrintInvoiceVer.exe " + TheNameOfTheFileYouCreatedThatHasTheXMLDataInIt
The name of the file should make the command line too long.... it'd be something like this:
PrintInvoiceVer.exe C:\Temp\SomeFile.xml
0
 
LVL 41

Expert Comment

by:graye
ID: 22894375
dang.... I missed a word
The name of the file should NOT make the command line too long.... it'd be something like this:
0
 
LVL 11

Author Comment

by:turn123
ID: 22894433
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question