1

I'm working on migrating my SVN repository to a new server. I have a PHP page that allows me to view the differences between two tags in an SVN repository. On this page you select the project, begin tag, end tag, and a couple other options. When you hit the "submit" button, a PowerShell script generates a new *.html page that summarizes the differences and returns the file name of the new html page. When I try to visit the PHP page on the new server, the browser hangs. I've isolated the issue to the shell_exec line. When I comment that out, the page loads as expected (but without actually calling the script).

I have made a test page to isolate potential problem code. The following code reproduces the issue while operating in a similar fashion to the original code. Note that my actual code stores the return as a variable and turns it into a link. I thought this may be causing problems so temporarily converted it to an echo output.

$proj = "ProjectName";
$btag = "2222Rev40";
$etag = "2222Rev45";
$bas = "Branch2222";
$diffd = "Code";
$buildCmd = "R:\\scripts\\buildlog.ps1 $proj $btag $etag $bas $diffd";
$cmd = "powershell.exe -InputFormat none -ExecutionPolicy unrestricted -NoProfile $buildCmd";
echo shell_exec($cmd);

As noted, the browser hangs when running the code above. Looking in task manager, I can see a PowerShell process that is spawned but never exits. When I remove echo shell_exec($cmd); and replace it with echo $cmd; I am able to see what command it is attempting to execute. Copying that output into a PowerShell terminal executes the script without any problems.

PS C:\Users\username> powershell.exe -InputFormat none -ExecutionPolicy unrestricted -NoProfile R:\scripts\buildlog.ps1 ProjectName 2222Rev40 2222Rev45 Branch2222 Code
20230606140531-ProjectName-2222Rev40-2222Rev45-Buildlog.html
PS C:\Users\username>

The generated *.html page also has all the expected informaiton/formatting so this does not seem to be an issue with the SVN calls.

Troubleshooting steps already tried:

  • Adding -InputFormat none to the PS call.
  • Modifying -ExecutionPolicy unrestricted in the PS call (previous code used RemoteSigned).
  • Adding -NoProfile to the PS call.
  • Updated the default ExecutionPolicy for both the x86 and x64 bit runtimes to unrestricted.
  • Created a test PS script that successfully runs using PHP (see note below).

Note: I found multiple similar questions asked on this site, most suggested the items tried above. I found Aaron Jenson's answer to this question to be particularly useful and I successfully implemented his recommended test setup. PHP can call and execute the get-process PowerShell script but not mine. The notable difference between his example and my sample code above is the use of positional command line arguments. To attempt to test this I just added nonsense positionals to his sample call (PS doesn't care if they aren't used). This was giving me problems with his format but I converted it to something that works. In the above code, if I replace buildlog.ps1 with test.ps1, I get the running processes displayed in my browser as expected.

Friedrich
  • 2,011
  • 2
  • 17
  • 19
TehDwArF
  • 11
  • 4
  • You can try debugging this yourself if you use [`proc_open`](https://www.php.net/manual/en/function.proc-open.php) instead of `shell_exec` and read from the streams in the `$pipes` reference array so you can check what's in the outputs while the script is running. It might have hints as to why it's stuck – apokryfos Jun 08 '23 at 17:09
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 09 '23 at 06:16

1 Answers1

0

Thanks to @apokryfos' suggestion I was able to make some progress in debugging due to the proc_open command. I found some sample code for how to use this here

I'm running into a error in my svn call now but that is unrelated to this question.

TehDwArF
  • 11
  • 4
  • This should go into a comment as it does not answer your question. Also, make sure to not only post a link, but also give some information about what we will find behind the link, e.g. add the key information directly to your answer in case the link becomes invalid. Anyway, welcome to the contributor side of SO :) – randmin Jun 13 '23 at 19:41