1

I am designing a winforms application to save some stuffs in PostgreSQL. In one part of my code I have to perform some PostgreSQL works like moving a table (named as serialnumbers) from one database (named as firstcards) to another (named as secondcards) and I have to use command prompt "cmd.exe" for the whole process.

The problem is; After sending a command to take the backup of table, I couldn't enter my db password to output of that command and thats why I couldn't go further to perform table transfer.

I checked this topic but actually what I want to learn is to perform tasks by answering the output of commands.

My code is:

        Process cmd = new Process();
        cmd.StartInfo.FileName = "cmd.exe";
        cmd.StartInfo.RedirectStandardInput = true;
        cmd.StartInfo.RedirectStandardOutput = true;
        cmd.StartInfo.CreateNoWindow = true;
        cmd.StartInfo.UseShellExecute = false;
        cmd.Start();
        cmd.StandardInput.WriteLine("cd\\ && cd program files\\postgresql\\10\\bin && pg_dump -h 127.0.0.1 -U postgres -Fc -b -v -t public.serialnumbers -f \"C:\\Users\\aetaser\\Desktop\\old\\table.backup\" firstcards"); // after sending this command, it returns an output to enter password
        cmd.StandardInput.Flush();
        cmd.StandardInput.WriteLine("1");// my db password
        cmd.StandardInput.Flush();
        cmd.StandardInput.WriteLine("cd\\ && cd program files\\postgresql\\10\\bin && pg_restore -h 127.0.0.1 -U postgres -v -d secondcards \"C:\\Users\\aetaser\\Desktop\\old\\table.backup\""); 
        cmd.StandardInput.Flush();
        cmd.StandardInput.WriteLine("1"); 
        cmd.StandardInput.Flush();
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tasher
  • 11
  • 2
  • I checked that topic but actually what i want to learn is to perform tasks by answering the output of commands. – Tasher Sep 14 '18 at 14:23

0 Answers0