By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,408 Members | 1,796 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,408 IT Pros & Developers. It's quick & easy.

Problem with Command Prompt Process

P: n/a
Dyl
Hi all,

I am having a problem with a command prompt process. It runs the cmd
prompt sucessfully, and changes the directory succesfully, but I can't
get the StartInfo.Arguments to work properly. My code is below, the
first stuff finds the most recently modified folder.

DirectoryInfo Direc = new DirectoryInfo(@"U:\MyFld\October");
DirectoryInfo[] FoldersArr = Direc.GetDirectories();

DateTime MostRecent = FoldersArr[0].LastWriteTime;
DirectoryInfo MostRecentDir = FoldersArr[0];

for (int i = 1; i < FoldersArr.Length; i++)
{
if (MostRecent.CompareTo(FoldersArr[i].LastWriteTime) < 0)
{
MostRecent = FoldersArr[i].LastWriteTime;
MostRecentDir = FoldersArr[i];
}
}

-------------------------Process-----------------------------------

Process proc = new Process();
proc.StartInfo.FileName = "cmd";
proc.StartInfo.WorkingDirectory = @Direc.FullName;
proc.StartInfo.Arguments = "compact /u /s:" +
MostRecentDir.Name;
proc.StartInfo.UseShellExecute = false;
proc.Start();

Nov 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
make sure that the directory name is enclosed with double quotes otherwise
spaces in the directory name (e.g. c:\program files\...) will cause
problems.

HTH

Ollie Riches
"Dyl" <mo****************@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi all,

I am having a problem with a command prompt process. It runs the cmd
prompt sucessfully, and changes the directory succesfully, but I can't
get the StartInfo.Arguments to work properly. My code is below, the
first stuff finds the most recently modified folder.

DirectoryInfo Direc = new DirectoryInfo(@"U:\MyFld\October");
DirectoryInfo[] FoldersArr = Direc.GetDirectories();

DateTime MostRecent = FoldersArr[0].LastWriteTime;
DirectoryInfo MostRecentDir = FoldersArr[0];

for (int i = 1; i < FoldersArr.Length; i++)
{
if (MostRecent.CompareTo(FoldersArr[i].LastWriteTime) < 0)
{
MostRecent = FoldersArr[i].LastWriteTime;
MostRecentDir = FoldersArr[i];
}
}

-------------------------Process-----------------------------------

Process proc = new Process();
proc.StartInfo.FileName = "cmd";
proc.StartInfo.WorkingDirectory = @Direc.FullName;
proc.StartInfo.Arguments = "compact /u /s:" +
MostRecentDir.Name;
proc.StartInfo.UseShellExecute = false;
proc.Start();

Nov 17 '05 #2

P: n/a
Dyl
Thanks for your reply Ollie,

But I am not sure where to put the double quotes in my code. You said
around the directory name, but could you specify where in my code?

Nov 17 '05 #3

P: n/a
try this:

proc.StartInfo.Arguments = "compact /u /s:\"" + MostRecentDir.Name + "\"";

HTH

Ollie Riches
"Dyl" <mo****************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks for your reply Ollie,

But I am not sure where to put the double quotes in my code. You said
around the directory name, but could you specify where in my code?

Nov 17 '05 #4

P: n/a
Dyl
Still no luck Ollie. The command still just pops up with a blinking
cursor.

Thanks though

Nov 17 '05 #5

P: n/a
so if you run it from the command line manually it works? if it does try
hardcoding an example in your application to make sure it works and then try
an example from your application manually from the command line - if any of
that makes any sense :)

Ollie Riches
"Dyl" <mo****************@yahoo.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Still no luck Ollie. The command still just pops up with a blinking
cursor.

Thanks though

Nov 17 '05 #6

P: n/a
Dyl
I hardcoded a specific case into my code, and it still does not work.
This time the window flashes, so I assume it's executing the command
but when I check to see if the folder is compressed, it is not. Is
there a way to keep the window from going away?

Thanks

Nov 17 '05 #7

P: n/a
Are you specifying a full path or a relative path, if a relative path then
try full path.

HTH

Ollie Riches

"Dyl" <mo****************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I hardcoded a specific case into my code, and it still does not work.
This time the window flashes, so I assume it's executing the command
but when I check to see if the folder is compressed, it is not. Is
there a way to keep the window from going away?

Thanks

Nov 17 '05 #8

P: n/a
Dyl
Hi Ollie,

Even when I hardcode something simple like "mkdir test," it still
doesn't work. This is very strange. I've looked at other posts, and
it seems my code is identical. Anyway, thanks again for your help.

-Dylan

Nov 17 '05 #9

P: n/a
Rag
try this

proc.StartInfo.Arguments = @"/c " + "compact /u /s:" +
MostRecentDir.Name;

Nov 17 '05 #10

P: n/a
Dyl
Rag,

That did it. Thanks for helping me. What does the /c do? Is that
current?

Thanks again.
Dylan

Nov 17 '05 #11

P: n/a
Here is another way to build the argument string

variable = @String.Concat("\"", arguments_here, "\"");

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.