|
-
January 6th, 2010, 05:58 AM
#1
Whats wrong with system.diagnostics
i want to delete file.txt
Code:
System.Diagnostics.Process.Start("cmd.exe", @"/c del d:\\file.txt");
but this is not deleting the file. any input?
-
January 6th, 2010, 06:37 AM
#2
Re: Whats wrong with system.diagnostics
and if you run this command alone, does it work?
also check the exit code
Code:
System.Diagnostics.Process.ExitCode
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 6th, 2010, 07:00 AM
#3
Re: Whats wrong with system.diagnostics
Why to do it in such a obscure way? Ins't File.Delete better?
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
January 6th, 2010, 07:01 AM
#4
Re: Whats wrong with system.diagnostics
 Originally Posted by boudino
Why to do it in such a obscure way?
for fun? to learn something new?
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 6th, 2010, 10:28 AM
#5
Re: Whats wrong with system.diagnostics
Maybe new forum could be established: toy fixing
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
January 7th, 2010, 01:19 AM
#6
Re: Whats wrong with system.diagnostics
this is my complete code
Code:
System.Diagnostics.Process.Start("cmd.exe", @"/c route print > d:\file.txt"); // Get the route print to text file
StreamReader streamReader = new StreamReader(filePath);
string readtext = streamReader.ReadToEnd();
streamReader.Close();
System.IO.File.Delete("d:\file.txt"); //Delete the output dump file
But i am getting error in the stream reader(filepath)
Code:
Could not find file 'd:\file.txt'..
the File is getting genereated
-
January 7th, 2010, 01:30 AM
#7
Re: Whats wrong with system.diagnostics
 Originally Posted by boudino
Why to do it in such a obscure way? Ins't File.Delete better?
i have started to do coing in c# just 4 days back. I want to get the route print command to be executed and get that to a file . So when i searched some forum, i got the reply to do with
Code:
System.Diagnostics.Process.Start
To delete also , i was trying the same way. i was not aware of the other option available. Now i moved code to file.delete . thanks for the help on that .
Is there a way i can run the command prompt from the c# other than what i have done using System.Diagnostics.Process.Start
-
January 7th, 2010, 02:14 AM
#8
Re: Whats wrong with system.diagnostics
 Originally Posted by makdu
Is there a way i can run the command prompt from the c# other than what i have done using System.Diagnostics.Process.Start
No.
-
January 7th, 2010, 02:28 AM
#9
Re: Whats wrong with system.diagnostics
The file is not getting deleted
Code:
System.Diagnostics.Process.Start("cmd.exe", @"/c route print > d:\file.txt"); // Get the route print to text file
using (StreamReader streamReader = File.OpenText(filePath))
{
string s = "";
if ((s = streamReader.ReadLine()) != null)
{
readtext = streamReader.ReadToEnd();// streamReader.ReadToEnd();
}
}
/* delete all unwanted files */
System.IO.File.Delete("d:\\file.txt"); //Delete the output dump file
also at first time rum ( after manually deleting the file.txt) , i am getting file not found error at
Code:
using (StreamReader streamReader = File.OpenText(filePath))
hERE IS my Complete code. This code some times work proplery by reading and writing ( when there is a breakpoint), some times it is not working
Code:
class Program
{
static void deletefiles()
{
System.IO.File.Delete("d:\\madavas1.txt");// delete madavas1.txt
System.IO.File.Delete("d:\\madavas2.txt");// delete madavas2.txt
System.IO.File.Delete("d:\\file.txt"); //Delete the output dump file
}
static void Main(string[] args)
{
string regMatch = "Active Routes:";//string to search for inside of text file. It is case sensitive.
string filePath = @"d:\file.txt";
string readtext = "";
string path = "";
bool found = false, last = false;
path = @"d:\\file.txt";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path)) // Create a file to write to madavas2.txt.
{
}
}
System.Diagnostics.Process.Start("cmd.exe", @"/c route print > d:\file.txt"); // Get the route print to text file
using (StreamReader streamReader = File.OpenText(filePath))
{
string s = "";
if ((s = streamReader.ReadLine()) != null)
{
readtext = streamReader.ReadToEnd();// streamReader.ReadToEnd();
}
}
/* delete all unwanted files */
deletefiles();
path = @"d:\\madavas1.txt";
if (!File.Exists(path))
{
// Create a file to write to madavas1.txt.
using (StreamWriter sw = File.CreateText(path))
{
}
}
path = @"d:\\madavas2.txt";
if (!File.Exists(path))
{
// Create a file to write to madavas2.txt.
using (StreamWriter sw = File.CreateText(path))
{
}
}
/* create mdavas2.txt for active route*/
StringReader madvas2 = new StringReader(readtext);
string madvas2temp = null;
while ((madvas2temp = madvas2.ReadLine()) != null)
{
if (Regex.IsMatch(madvas2temp, regMatch))
{
found = !found;
}
if (found)
{
if (Regex.IsMatch(madvas2temp, "======"))
{
found = false;
break;
}
System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\madavas2.txt", true);
file.WriteLine(madvas2temp);
file.Close();
}
}
madvas2.Close();
/* create mdavas1.txt for persistent route*/
StringReader madvas1 = new StringReader(readtext);
string madvas1temp = null;
regMatch = "Persistent Routes:";
while ((madvas1temp = madvas1.ReadLine()) != null)
{
if (Regex.IsMatch(madvas1temp, regMatch))
{
found = !found;
}
if (found || last)
{
if (Regex.IsMatch(madvas1temp, "======"))
{
found = false;
break;
}
System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\madavas1.txt", true);
file.WriteLine(madvas1temp);
file.Close();
}
}
madvas1.Close();
List<string[]> sl = new List<string[]>();
string temp2;
string[] delim = { " " };
Int32 testvalue = 0;
using (StreamReader sr = new StreamReader("d:\\madavas2.txt"))
{
while ((temp2 = sr.ReadLine()) != null)
{
sl.Add(temp2.Split(delim, StringSplitOptions.RemoveEmptyEntries));
// testvalue=int32.parse(s1(0));
}
testvalue = Int32.Parse(sl[2][4]);
}
deletefiles();
}
}
Is it something to do with the timer?
Last edited by makdu; January 7th, 2010 at 02:45 AM.
-
January 16th, 2010, 07:34 AM
#10
Re: Whats wrong with system.diagnostics
try to call
Code:
System.Diagnostics.Process.WaitForExit();
right after
Code:
System.Diagnostics.Process.Start("cmd.exe", @"/c route print > d:\file.txt"); // Get the route print to text file
System.Diagnostics.Process.WaitForExit()
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|