0

I am trying to call the PHP file by, passing the request_number in the localhost URL using Powershell

In HTML:

<a href='workflow_execution_progress.php?view_id=".$row['request_number']."' title='Click to see the progress of workflow'>

I referred to this link but not sure to modify it with parameters. Executing php script on powershell

Update: My PowerShell

$PhpExe  = "C:\path\to\php\install\dir\php.exe"
$PhpFile = "C:\path\to\script.php"
$PhpArgs = '-f "{0}"' -f $PhpFile  //args like view_id = 1 / 2 /3 (dynamically)
$PhpOutput = & $PhpExe $PhpArgs
Anu Priya
  • 33
  • 1
  • 1
  • 9
  • If you call a local PHP file through powershell, then there's not "url" involve (since you're not making a network request). – M. Eriksson Oct 14 '20 at 11:59
  • yup, it's a local file now. will deploy after the completion of the project. My question is how to pass dynamic id to the PHP file using PowerShell script @MagnusEriksson – Anu Priya Oct 14 '20 at 12:03
  • Does this answer your question? [Pass variable to php script running from command line](https://stackoverflow.com/questions/6826718/pass-variable-to-php-script-running-from-command-line) – M. Eriksson Oct 14 '20 at 12:34
  • @MagnusEriksson Sorry i am not getting how i can add it in my powershellcode $PhpExe = "C:\path\to\php\install\dir\php.exe" $PhpFile = "C:\path\to\script.php" $PhpArgs = '-f "{0}"' -f $PhpFile – Anu Priya Oct 14 '20 at 12:53

1 Answers1

1

You can use $argv to get an array of arguments passed to the script.

https://www.php.net/manual/en/reserved.variables.argv.php

php script.php arg1 arg2 arg3

<?php
var_dump($argv);
?>

array(4) {
  [0]=>
  string(10) "script.php"
  [1]=>
  string(4) "arg1"
  [2]=>
  string(4) "arg2"
  [3]=>
  string(4) "arg3"
}

magrigry
  • 405
  • 2
  • 8
  • Sorry i am not getting how i can add it in my powershellcode $PhpExe = "C:\path\to\php\install\dir\php.exe" $PhpFile = "C:\path\to\script.php" $PhpArgs = '-f "{0}"' -f $PhpFile – Anu Priya Oct 14 '20 at 12:51
  • Maybe I did not understand your problem. I am not sure if it is about how to get the argument passed to the script, or how to pass arguments ? – magrigry Oct 14 '20 at 13:12
  • Need to pass arguments to the PHP file using powershell script. - how to pass arguments – Anu Priya Oct 14 '20 at 13:24
  • I don't get it. I read your update but why not just place arguments after $Phpfile ? $PhpArgs = '-f "{0}"' -f $PhpFile 'view_id=1' – magrigry Oct 14 '20 at 13:34