1

I would like to create small applications to manage my projects, should work so that after you select an item from the list of projects then the console changes the current directory to the project and exits program leaving you console in corect dir, then you can run, for example, vs code or http-server.

I tryed
Environment.CurrentDirectory = direcory
Directory.SetCurrentDirectory(directory)
neither of it worked for me :/

Maciej Kozieja
  • 1,812
  • 1
  • 13
  • 32
  • 5
    I don't think you can do that, once the c# app terminates you can't keep it open. You can open a command prompt from c# and pass it a change directory command. http://stackoverflow.com/questions/1469764/run-command-prompt-commands – Rick S Jan 30 '17 at 14:55
  • Your console app and whatever-else-you-want-to-run will execute in difference processes, so will have different "current directories". One will not affect the other. – Matthew Layton Jan 30 '17 at 14:57
  • A [batch](https://en.wikibooks.org/wiki/Windows_Batch_Scripting#CD) would be better suited, I guess. – Fildor Jan 30 '17 at 15:00
  • yes i had batch script but i fougth that adding some with live filtering while typing would be nice because i don't remember all names – Maciej Kozieja Jan 30 '17 at 20:13
  • so mamy is there a way to pass c# program "execution result" to batch ? – Maciej Kozieja Jan 30 '17 at 20:19

2 Answers2

0

I think this should do the trick. Also, you can execute some command on it from the code:

var startInfo = new ProcessStartInfo
{
    WorkingDirectory = @"SomeDirectory",
    FileName = "cmd.exe",
    // Arguments = "start http-server"
};
var process = new Process {StartInfo = startInfo};
process.Start();
blaz11
  • 23
  • 1
  • 7
0

If I understand your question correctly, essentially you want to write a C# program that performs a similar function to the CD command in the Command Prompt environment.

Unfortunately you cannot do this from C# program as the program is started in its own isolated AppDomain, which is thrown away (along with your new working directory) when your program completes. On top of this you cannot influence the creation of the AppDomain by the launching process (the command prompt).

SpaceUser7448
  • 189
  • 1
  • 10