Git Product home page Git Product logo

Comments (8)

merlinthemagic avatar merlinthemagic commented on May 27, 2024 1

Hi,

Turns out i have let us on a bit of a wild goose chase, mostly because exec() is so vague in its return. The help for "where" states:

  NOTE: The tool returns an error level of 0 if the search is
        successful, of 1 if the search is unsuccessful and
        of 2 for failures or errors.

Since you received a return code 1 when running "where powershell" in your first reply to this issue, it appears "where" is available in your environment, but it was unsuccessful in locating "powershell.exe".

Now this issue gets really wonky, because you just confirmed "where" is able to locate "powershell.exe", but only when you use the absolute path for "where". I have zero idea why that is.

Are you 100% sure you are executing using the same user/environment when running MTS and when triggering the exec() commands above? Is it possible MTS is running on a server and the exec() commands are executed on your local dev box? Its a silly question, but none of this makes sense because by default "where" will search the current directory and the environment path. There is no indication that behavior changes depending on if "where" is triggered with or without an absolute path.

Back to the issue at hand, your PHP user needs the powershell directory path in the PATH variable for the environment. You can check if it is by running:

exec("echo %PATH%", $data, $status);

OR just:

exec("path", $data, $status);

Somewhere in the $data return you should see:

C:\Windows\System32\WindowsPowerShell\v1.0\

If it is not there you can either append it to the system path (best option) or do it at runtime before executing MTS:

exec("setx PATH \"C:\Windows\System32\WindowsPowerShell\v1.0\;%PATH%\"", $data, $status);

There is a chance your path variable is larger than 1024 chars, in that case read this.

Good luck.

from mts.

merlinthemagic avatar merlinthemagic commented on May 27, 2024

Hi,

What is the return when you execute (as PHP user) on cmd?
where powershell

Just use exec(), that will mimic the execution done by the lib:
exec("where powershell", $data, $status);
Whats in $data and $status after execution?

from mts.

oriceon avatar oriceon commented on May 27, 2024

On cmd i get:

λ where powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

And on browser:

[]
1

from mts.

merlinthemagic avatar merlinthemagic commented on May 27, 2024

Hi,

Return code 1 means the command encountered an error. exec() is not super verbose when it comes to returning error messages.

Chances are your php user is locked to a subset of commands, or unable to traverse up the filesystem. Both pretty good practices for any public facing service.

Try to determine if this is a general exec() permissions issue or a power shell specific issue what does each of the following commands return if triggered through php exec()? if no return please provide return straight from cmd.

whoami
wmic OS get Name
wmic OS get OSArchitecture
cd
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command "Get-Host | Select-Object Version"

from mts.

oriceon avatar oriceon commented on May 27, 2024
1) whoami

Browser: array:1 [▼
  0 => "nt authority\system"
]
0

CMD: My\Name


2) wmic OS get Name

Browser: array:3 [▼
  0 => "Name"
  1 => "Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk0\Partition4"
  2 => ""
]
0

CMD: 
Name
Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk0\Partition4


3) wmic OS get OSArchitecture

Browser: array:3 [▼
  0 => "OSArchitecture"
  1 => "64-bit"
  2 => ""
]
0

CMD:
OSArchitecture
64-bit


4) cd

Browser: array:1 [▼
  0 => "C:\Dev\www\public"
]
0

CMD: C:\Dev\www


5) C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command "Get-Host | Select-Object Version"

Browser: array:6 [▼
  0 => ""
  1 => "Version"
  2 => "-------"
  3 => "5.1.19041.1023"
  4 => ""
  5 => ""
]
0

CMD: 
Version
-------
5.1.19041.1023

from mts.

merlinthemagic avatar merlinthemagic commented on May 27, 2024

Hi,

Thats just downright strange. Appears where is not in the environment path for the server.

Return of these last two commands please:

dir C:\Windows\System32\where.exe

C:\Windows\System32\where.exe powershell

from mts.

oriceon avatar oriceon commented on May 27, 2024

Hi.

1)

Browser:
    Directory: C:\Windows\System32

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        07.12.2019     11:09          43008 where.exe


CMD:
 Volume in drive C is Windows
 Volume Serial Number is A243-E3BB

 Directory of C:\Windows\System32

07.12.2019  12:09            43.008 where.exe
               1 File(s)         43.008 bytes


2)

Browser:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

CMD:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

from mts.

plonknimbuzz avatar plonknimbuzz commented on May 27, 2024

Hi,

Turns out i have let us on a bit of a wild goose chase, mostly because exec() is so vague in its return. The help for "where" states:

  NOTE: The tool returns an error level of 0 if the search is
        successful, of 1 if the search is unsuccessful and
        of 2 for failures or errors.

Since you received a return code 1 when running "where powershell" in your first reply to this issue, it appears "where" is available in your environment, but it was unsuccessful in locating "powershell.exe".

Now this issue gets really wonky, because you just confirmed "where" is able to locate "powershell.exe", but only when you use the absolute path for "where". I have zero idea why that is.

Are you 100% sure you are executing using the same user/environment when running MTS and when triggering the exec() commands above? Is it possible MTS is running on a server and the exec() commands are executed on your local dev box? Its a silly question, but none of this makes sense because by default "where" will search the current directory and the environment path. There is no indication that behavior changes depending on if "where" is triggered with or without an absolute path.

Back to the issue at hand, your PHP user needs the powershell directory path in the PATH variable for the environment. You can check if it is by running:

exec("echo %PATH%", $data, $status);

OR just:

exec("path", $data, $status);

Somewhere in the $data return you should see:

C:\Windows\System32\WindowsPowerShell\v1.0\

If it is not there you can either append it to the system path (best option) or do it at runtime before executing MTS:

exec("setx PATH \"C:\Windows\System32\WindowsPowerShell\v1.0\;%PATH%\"", $data, $status);

There is a chance your path variable is larger than 1024 chars, in that case read this.

Good luck.

in some case we need to restart our windows to get some Environment
restart apache not gonna help
but in my experience the probability is just 5%

@merlinthemagic answer will gonna help a lot to debug the environment, so i think this issue can be marked as solved, because this is not MTS issue, but only local system issue

from mts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.