html out について。
Q&A
ps_test1.cgi
#! C:/Program Files/PowerShell/7/pwsh
$OutputEncoding = [System.Text.Encoding]::utf8NoBOM
# http://127.0.0.1/ps_test/ps_test1.cgi
$this_out = @"Content-type: text/html;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test PowerShell CGI Script</title>
</head>
<body>
<h1>test</h1>
</body>
</html>
"@
cd "C:\Apache\Apache2.2\htdocs\ps_test\"
$thisPath = "ps_test1.cgi"
Start-Process "msedge.exe" $thisPath
"https://localhost/ps_test/" | ForEach-Object { Start-Process "msedge.exe" $thisPath }
exit 0
error.log
[Tue Aug 19 11:56:01 2025] [error] [client 127.0.0.1] Premature end of script headers: ps_test1.cgi
acsesu.log
127.0.0.1 - - [19/Aug/2025:11:56:01 +0900] "GET /ps_test/ps_test1.cgi HTTP/1.1" 500 536
環境 Apache2.2 PowerShell7.6 ブラウザedge
fast try
ps_test.cgi
#! C:/Program Files/PowerShell/7/pwsh
$OutputEncoding = [System.Text.Encoding]::utf8NoBOM
# #! C:/Program Files/PowerShell/7/pwsh -utf8NoBOM
####### test PowerShell 7 コンソール test #######
# 立ち上がり後utf-8化しています。ファイルはutf-8で保存しておいてください。
# この場合UTF8なのかUTF-8なのか抑えた方がいいがシェルコマンドの-は要素となる2要素になる。
# http://127.0.0.1/ps_test/ps_test.cgi
# これはコメントです
echo Content-type: text/html;
echo
$hedder = @"<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test PowerShell CGI Script</title>
</head>
<body>
"@
echo $hedder
# body erement
Write-Output "こんにちは" # これは出力コマンドです
$futtr = @"
</body>
</html>
@"
echo $futtr
# this cgi out last display.
exit 0
# free PowerShell workig.
$html = @"Content-type: text/html;
<html>
<head><title>Test</title></head>
<body><h1>こんにちは、にゃんにゃんさん</h1></body>
</html>
"@
# 生成アドレスへパイプで送り込む 仮想ファイル空間
cd "C:\Apache\Apache2.2\htdocs\ps_test\"
echo 出力待機中。
Read-Host "続行するには Enter キーを押してください"
$tempPath = "ps_test.html"
$html | Set-Content -Path $tempPath -Encoding utf8NoBOM
echo 第二待機、併設ブラウザに出力待ち。
$tempPath = "ps_test.html"
cmd /c pause
Start-Process "msedge.exe" $tempPath
"https://localhost/ps_test/" | ForEach-Object { Start-Process "msedge.exe" $tempPath }
echo 第3待機、ブラウザに出力待ち。何も送らず待機しますこのファイルが起きます。
cmd /c pause
$scriptPath = "C:\Apache\Apache2.2\htdocs\ps_test\my_form_fast.ps1"
& $scriptPath
exit 0
on sell taminal view opne.try.
やってはいますが上手く行きません。
1 likes