0

I am working on a C# .net core project.I created a process to run "xdotool windowactivate $windowpid".I should store the windowID which process run on it.The solution could be any property of xdotool which i couldn't find,or Is there any way to take windowId of a process when it is created?

Another Try is that: I created my pages with this method. I tried to take mainwindowtitle of process;because of single process,i couldn't take the titles.

 static List<string> chromeTitles = new List<string>();
 public static Process StartChrome(string filePath)
 {  
            

            string dataDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Chrome-UserData");
            filePath += " --user-data-dir=" + dataDirectory;
            var Chrome = new Process
            {
                StartInfo =
                {
                    FileName = "C:/Program/chrome.exe",
                    Arguments =  filePath,
                    UseShellExecute = false,
                    CreateNoWindow=true,
                    WindowStyle = ProcessWindowStyle.Maximized,                    
                }
             
            };
            Chrome.Start();
            string title = Chrome.MainWindowTitle;
            chromeTitles.Add(title);
 }

Then I call it :

 StartChrome("https://tr.wikipedia.org/wiki/Anasayfa");
 Thread.Sleep(2000);
 StartChrome("https://tureng.com/");
sum
  • 1
  • 3

1 Answers1

0

You can use the Process class for accessing more capabilities.

        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.FileName = "xdotool.exe";
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = $"windowactivate $windowpid";
        process.StartInfo = startInfo;
        process.Start();

To get the PID of the process that got run by the code, you can use Process.ID property:

process.Id;

if you want to read the output, you can add this code:

string output = process.StandardOutput.ReadToEnd();

To get Output, startInfo.RedirectStandardOutput should be True.

Y sharifpour
  • 361
  • 4
  • 12
  • I created 2 chrome page.They have same processID.Thats why i couldn't get top the page which i want.I tried it with mainWindowTitle but the result is the same,because title is also depends on the process.In addition title property doesn't have set .Do you have any suggestion to this problem? – sum Apr 09 '21 at 09:02
  • How do you create chrome pages? Could you also add those codes with an appropriate explanation? – Y sharifpour Apr 10 '21 at 22:54
  • You can't close a google chrome tab with PID. Why don't you use the selenium library to control google chrome? – Y sharifpour Apr 12 '21 at 09:24
  • Thank you for suggestion.Should I run it in Linux? – sum Apr 13 '21 at 07:23