[Laravel] run CMD command

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • Groax
  • Registratie: Oktober 2012
  • Laatst online: 02-10 11:33
Mijn vraag
Voor een project moet ik een cmd uitvoeren om iets in werking te stellen.
Ipconfig is alleen op te testen.

Er wordt een string gegenereerd die zal de taak moeten gaan vervullen.
Weet iemand hoe ik dit kan laten werken?

PHP:
1
2
3
4
5
6
7
$process = new Process(['ipconfig']);
$process->run();

if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}
$process->getOutput();


Dit krijg ik terug
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
The command "ipconfig" failed.

Exit Code: 1(General error)

Working directory: ******************

Output:
================


Error Output:
================
'ipconfig' is not recognized as an internal or external command,
operable program or batch file.
"""



Relevante software en hardware die ik gebruik
Dit zou ook werken maar wil het het laten werken zodat ik de commando's kan wijzigen en dat ik foutmeldingen kan genereren als iets niet werkt.

Wat ik al gevonden of geprobeerd heb
https://symfony.com/doc/current/components/process.html
https://www.php.net/manual/en/book.exec.php
https://laracasts.com/dis...a-laravel-artisan-console

Beste antwoord (via Groax op 19-08-2019 01:01)


  • Tokkes
  • Registratie: September 2011
  • Laatst online: 12-12-2022
Nou ben ik niet thuis in Laravel, maar lijkt mij dat je omgeving niet weet waar te kijken.

Als jij CMD opstart, heb je namelijk onder andere de $PATH environment variable waar C:\Windows\System32\ in zal zitten. In die sys32 map zit de ipconfig executable. Door de $PATH envvar weet CMD / PoSH / ... in welke folder(s) de executable te zoeken

Dus ofwel helemaal je executable uitschrijven qua filename, ofwel eventueel je $PATH envvar initialiseren.

Durf te wedden dat als je gewoon 'PATH' uitvoert via die laravel, dat je een lege variabele terugkrijgt.

code:
1
2
3
4
5
C:\Users\tomge>where ipconfig
C:\Windows\System32\ipconfig.exe

C:\Users\tomge>PATH
PATH=C:\Program Files (x86)\Python\Python37-32\Scripts\;C:\Program Files (x86)\Python\Python37-32\;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Users\tomge\AppData\Local\Microsoft\WindowsApps;C:\Users\tomge\AppData\Local\atom\bin

[ Voor 3% gewijzigd door Tokkes op 19-08-2019 00:59 ]

GoTBF3 Race topic! -- Battlelog - Battalion'44 Servers :10Slots Wartide 213.32.98.194:7777 - TDM = 213.32.98.194:7781

Alle reacties


Acties:
  • +1 Henk 'm!

  • danslo
  • Registratie: Januari 2003
  • Laatst online: 19:13
ipconfig is specifiek windows, waar draai je dit op? Op linux is dit doorgaans ifconfig (let op de f).

Acties:
  • 0 Henk 'm!

  • Groax
  • Registratie: Oktober 2012
  • Laatst online: 02-10 11:33
danslo schreef op maandag 19 augustus 2019 @ 00:45:
ipconfig is specifiek windows, waar draai je dit op? Op linux is dit doorgaans ifconfig (let op de f).
Gewoon Windows :)

Acties:
  • Beste antwoord
  • 0 Henk 'm!

  • Tokkes
  • Registratie: September 2011
  • Laatst online: 12-12-2022
Nou ben ik niet thuis in Laravel, maar lijkt mij dat je omgeving niet weet waar te kijken.

Als jij CMD opstart, heb je namelijk onder andere de $PATH environment variable waar C:\Windows\System32\ in zal zitten. In die sys32 map zit de ipconfig executable. Door de $PATH envvar weet CMD / PoSH / ... in welke folder(s) de executable te zoeken

Dus ofwel helemaal je executable uitschrijven qua filename, ofwel eventueel je $PATH envvar initialiseren.

Durf te wedden dat als je gewoon 'PATH' uitvoert via die laravel, dat je een lege variabele terugkrijgt.

code:
1
2
3
4
5
C:\Users\tomge>where ipconfig
C:\Windows\System32\ipconfig.exe

C:\Users\tomge>PATH
PATH=C:\Program Files (x86)\Python\Python37-32\Scripts\;C:\Program Files (x86)\Python\Python37-32\;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Users\tomge\AppData\Local\Microsoft\WindowsApps;C:\Users\tomge\AppData\Local\atom\bin

[ Voor 3% gewijzigd door Tokkes op 19-08-2019 00:59 ]

GoTBF3 Race topic! -- Battlelog - Battalion'44 Servers :10Slots Wartide 213.32.98.194:7777 - TDM = 213.32.98.194:7781


Acties:
  • 0 Henk 'm!

  • Groax
  • Registratie: Oktober 2012
  • Laatst online: 02-10 11:33
Verdomd..... hier heb ik dus echt niet aan gedacht.... BEDANKT dit werkt :)

Acties:
  • +1 Henk 'm!

  • Tokkes
  • Registratie: September 2011
  • Laatst online: 12-12-2022
Vergeet je nooit meer na vandaag ;)

GoTBF3 Race topic! -- Battlelog - Battalion'44 Servers :10Slots Wartide 213.32.98.194:7777 - TDM = 213.32.98.194:7781

Pagina: 1