File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1747,7 +1747,7 @@ protected override void GetProperties(Hashtable propertyDescriptors)
17471747
17481748 NpgsqlConnectionStringBuilder ? GetConfigFromIniFile ( string ? filePath )
17491749 {
1750- if ( filePath is null || ! File . Exists ( filePath ) )
1750+ if ( filePath is null || ! File . Exists ( filePath ) )
17511751 {
17521752 return null ;
17531753 }
Original file line number Diff line number Diff line change 11using System ;
2+ using System . Diagnostics ;
23using System . IO ;
34using System . Runtime . InteropServices ;
45
@@ -81,5 +82,27 @@ internal static string? SslCertRootDefault
8182
8283 static string ? GetSystemPostgresDir ( ) => Environment . GetEnvironmentVariable ( "PGSYSCONFDIR" ) ;
8384
84- static string ? GetDefaultSystemPostgresDir ( ) => default ; // Retrieve from "pg_config --sysconfdir"
85+ static string ? GetDefaultSystemPostgresDir ( ) => ExecuteCommandSync ( "pg_config" , "--sysconfdir" ) ;
86+
87+ static string ? ExecuteCommandSync ( string command , string arguments )
88+ {
89+ try
90+ {
91+ using var process = new Process ( ) ;
92+ process . StartInfo . FileName = command ;
93+ process . StartInfo . Arguments = arguments ;
94+ process . StartInfo . RedirectStandardOutput = true ;
95+ process . StartInfo . UseShellExecute = false ;
96+ process . Start ( ) ;
97+
98+ var output = process . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
99+ process . WaitForExit ( ) ;
100+
101+ return process . ExitCode == 0 ? output : null ;
102+ }
103+ catch ( Exception )
104+ {
105+ return null ;
106+ }
107+ }
85108}
You can’t perform that action at this time.
0 commit comments