peter-h
Goto Top

PHP Ausdruck über shell-exec()

Hallo zusammen,

ich möchte auf einer PHP-Seite automatisch einen Ausdruck über einen Shell-Befehl starten.

Windows Power Shell-Befehl in Power Shell ausgeführt:
"Hello, World" | Out-Printer
- Ausdruck funktioniert

Jetzt das PHP-Script
$output= shell_exec('"Hello, World" | Out-Printer');
echo $output;

- das Script funktioniert nicht!
- An Stelle "Hello, World" wollte ich auch noch eine $string Variable übergeben.

Dieses Script funktioniert in PHP - wird richtig ausgeführt
$output= shell_exec('ipconfig');
echo $output;

Danke schon mal für Eure Unterstützung
Peter

Content-Key: 63326224650

Url: https://administrator.de/contentid/63326224650

Printed on: April 30, 2024 at 23:04 o'clock

Mitglied: 12168552861
Solution 12168552861 Apr 11, 2024 updated at 07:50:16 (UTC)
Goto Top
$string = "Hello World";  
$output = shell_exec('powershell -EP Bypass -C "\"' . $string . '\" | Out-Printer"');  
echo $output;

Dir sollte aber schon klar sein das du da noch mehr Sicherheitsvorkehrungen und Eingabeprüfungen einbauen musst, sowas ist immer brand gefährlich ohne weitere Maßnahmen ...

Gruß
Member: Peter-H
Peter-H Apr 11, 2024 at 07:56:06 (UTC)
Goto Top
Super Danke
und wie bekomme ich noch eine Variable übergeben
z.B.
$string = "<p>irgendwas</p>"; anstatt "\"Hello, World\"

$output = shell_exec('powershell -EP Bypass -C "\"Hello, World\" | Out-Printer"');
echo $output;
Mitglied: 12168552861
12168552861 Apr 11, 2024 updated at 07:58:10 (UTC)
Goto Top
und wie bekomme ich noch eine Variable übergeben
S.o.
Member: Peter-H
Peter-H Apr 11, 2024 at 08:18:24 (UTC)
Goto Top
Danke meisterroehrich ,
geht einwandfrei.
Die Sicherheitslücke ist mir bewusst, das Script dient lediglich zum Etikettenausdruck.
Die Variablen gebe ich vor....

Danke nochmals
Member: Peter-H
Peter-H Apr 11, 2024 at 09:23:11 (UTC)
Goto Top
Eine frage noch
ist es auch möglich eine Tabelle als $string auszudrücken

$string="
<table border='1' cellpadding='5' cellspacing='0' width='530'>
<tr>
<td>Zelle 1</td><td>Zelle 2</td><td>Zelle 3</td>
</tr>
<tr>
<td>Zelle 1</td><td>Zelle 2</td><td>Zelle 3</td>
</tr>
<tr>
<td>Zelle 1</td><td>Zelle 2</td><td>Zelle 3</td>
</tr>
</table>
";

$output = shell_exec('powershell -EP Bypass -C "\"' . $string . '\" | Out-Printer"');
echo $output;

oder sollte ich lieber alles mit einer PDF-Lösung machen
dann wäre die Frage wie lautet der Befehl zum shell_exec(Ausdruck einer PDF-Datei)?
Mitglied: 12168552861
12168552861 Apr 11, 2024 updated at 09:28:58 (UTC)
Goto Top
dann wäre die Frage wie lautet der Befehl zum shell_exec(Ausdruck einer PDF-Datei)?
Kann Out-Printer nicht.
Member: wiesi200
wiesi200 Apr 12, 2024 at 07:13:16 (UTC)
Goto Top
Hallo,
bei Etiketten um welchen Drucker geht es da. Zebra hat z.b ZPL als Scriptsprache zum Ansteuern.
Member: Peter-H
Peter-H Apr 12, 2024 at 07:25:24 (UTC)
Goto Top
Hi,
Es handelt sich um gewöhnliche Laserdrucker
Brother u Kyocera

Habs jetzt so gelöst
$pdfname="test.pdf";
$output = shell_exec('powershell -EP Bypass -C "Start-Process –FilePath \"' . $pdfname . '\" –Verb Print"');
echo $output;

funktioniert.
Im Etiketten-Formular lass ich noch zusätzlich den Drucker auswählen und def. Diesen dann als Standard. Das ganze wird dann als PDF-ausgedruckt.