3

I am trying to run this:

shell_exec("powershell -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername > /dev/null &");

It works fine as long as I remove:

/dev/null &

However, that makes the website pause and wait for the script to finish. When I have that included, the script never runs.

I have also tried this and it stops the ps1 from running as well:

/dev/null 2>&1 &

Edit: I need a way to have my php run a powershell script on a windows server and not wait for the response. Waiting causes my website to hang and prevents the users from running a new command. I researched and found the above solutions, but someone has pointed out that those are for linux servers. Is there another way to execute my powershell script and not wait for a response?

Edit2: I can't get the powershell to launch at all now, the sql command runs fine and the page refreshes, but the powershell never runs, here is the code:

<?php
if(isset($_POST['Submit'])) {
    $connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password");
    $conn = sqlsrv_connect( "server", $connectionInfo);
    $params = array();
    $username = $_SERVER['AUTH_USER'];
    $computername = $_POST['CName'];
    $time = date("m/d - g:i a");
    $sql2 = "INSERT INTO dbo.Installs (Hostname, Status, Username, Time) VALUES (?, ?, ?, ?)";
    $var = array($computername, "InProgress", $username, $time);
    sqlsrv_query($conn, $sql2, $var);
    sqlsrv_close($conn);

    shell_exec("powershell.exe -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername");
    sleep(5);

    header("Refresh:0");
}
?>
5
  • 5
    Windows has no such thing as /dev/null. Commented Oct 18, 2016 at 12:35
  • Ah, well that's unfortunate. That explains why it doesn't work. Commented Oct 18, 2016 at 12:36
  • > NUL is supposed to be the same in windows Commented Oct 18, 2016 at 12:37
  • Possible duplicate of PHP to Powershell using shell_exec Commented Oct 18, 2016 at 12:41
  • This is not a duplicate issue of the one you linked Koen. Commented Oct 18, 2016 at 12:46

1 Answer 1

0

There is no solution for this problem. This is a security measure in IIS that I don't want to spend the time trying to go around. I have gone a different route for this, Thanks for all the help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.