0

I'm receiving an output error while trying to redirect a process input from a file - reading the file content and writing it to the process input. the error: <output file> The volume for a file has been externally altered so that the opened file is no longer valid.

the code:

*before foreach loop:

  prc = new Process();
  prc.StartInfo.FileName = prcs;
  prc.StartInfo.UseShellExecute = false;

*inside foreachloop:

  prc = new Process();
  prc.StartInfo.FileName = prcs;
  prc.StartInfo.UseShellExecute = false;
  if (prcs == asProcesses[0])//first process - only redirect output
  {
      prc.StartInfo.RedirectStandardInput = true;
      prc.StartInfo.RedirectStandardOutput = true;
      prc.Start();
      sw = prc.StandardInput;
      StreamReader sr1 = new StreamReader(sInRedirect);
      while ((outputLine = sr1.ReadLine()) != null)
      {
           sw.Write(outputLine);
           sw.WriteLine();
      }
      sr = prc.StandardOutput;
      }

* i get the message while writing the command: "text1.txt < sort"

  • another thing, if i run the program in another computer i get the message: " the pipe is being closed" thank you for your help!
shiran bar
  • 29
  • 2
  • 8
  • What kind of location are you writing the file to? – Oded Mar 02 '11 at 20:49
  • That's not what I am asking. What is `sInRedirect`? What kind of location? – Oded Mar 02 '11 at 20:59
  • its a text file, but i'm trying to write the content of the text file to the process'input – shiran bar Mar 02 '11 at 21:15
  • This is the third question on this assignment, stackoverflow seems to be really popular in your grade ;-) Read the comments at [Execute Process Chain](http://stackoverflow.com/questions/5170273/execute-process-chain) and my answer at [how can i check if the process got output?](http://stackoverflow.com/questions/5171945/how-can-i-check-if-the-process-got-output). – Tamschi Mar 03 '11 at 01:52
  • yeah apparently :), though my problem is with reading from a file and not with the piping itself – shiran bar Mar 03 '11 at 12:44
  • Can you use a `try ... catch` to catch the error? If not then it's definitely a problem with Visual Studio and has nothing to do with your program. – Tamschi Mar 03 '11 at 19:46

1 Answers1

0

It seems that the permission on your output directory are set in a way that prevents Visual Studio from compiling.
Remove any read-only flags from the project's folder and all subdirectories, clear the output folder and, if necessary, take ownership of the folders or give yourself full permissions.

Source: msdn - Visual Studio 2010 fails to build or debug reports error 'Failed to write to output file'.

Tamschi
  • 1,089
  • 7
  • 23
  • i read that one as well, i removed the read-only flags and emptied the bin/debug folder, yet it doesn't work – shiran bar Mar 03 '11 at 14:42