[ CCode ( cname = "g_find_program_in_path" ) ]
public string? find_program_in_path (string program)

Locates the first executable named program in the user's path, in the same way that execvp would locate it.

Returns an allocated string with the absolute path name, or null if the program is not found in the path. If program is already an absolute path, returns a copy of program if program exists and is executable, and null otherwise.

On Windows, if program does not have a file type suffix, tries with the suffixes .exe, .cmd, .bat and .com, and the suffixes in the `PATHEXT` environment variable.

On Windows, it looks for the file in the same way as CreateProcess would. This means first in the directory where the executing program was loaded from, then in the current directory, then in the Windows 32-bit system directory, then in the Windows directory, and finally in the directories in the `PATH` environment variable. If the program is found, the return value contains the full name including the type suffix.

Example: Locate the executable:

public static int main (string[] args) {
// Local output: ``/usr/bin/ls``
string? path = Environment.find_program_in_path ("ls");
print ("%s\n", path);

// Local output: ``(null)``
path = Environment.find_program_in_path ("dummy-application-123");
print ("%s\n", path);

return 0;

valac --pkg glib-2.0 GLib.Environment.find_program_in_path.vala



a program name in the GLib file name encoding


a newly-allocated string with the absolute path, or null

Namespace: GLib.Environment
Package: glib-2.0