For example, I want change PC time in console.
C:\Users\user>time
The current time is: 15:25:21,04
Enter the new time:
PHP:
exec('time', $out, $ret);
/*
$out =
The current time is: 15:25:21,04
Enter the new time:
*/
How to send new time ?
Upd
Without 1 line commands echo <timestring> | time
#Thx to reox
#Working example:
$next_hour = date('H:i:s', strtotime('+1 hour'));
$command = 'time';
$handle = popen($command, 'r');
echo 'Command responce: <br>';
while($line = fgets($handle)) {
echo $line;
echo '<br>';
}
pclose($handle);
$handle = popen($command, 'w');
fputs($handle, $next_hour);
pclose($handle);
The
timeconsole application expects input at standard input (STDIN), that’s the standard input for console applications (so this is true for any other standard commandline (CLI) application as well, not only time):Should do the trick, the pipe symbol
|redirects the output fromechoas input totime. That’s a common principle for both windows and unix.