我有一个脚本接受一个路径列表,作为一个字符串数组进行处理.我正在用它Get-ChildItem来生成这些路径.我在从System.IO.FileInfo对象到字符串的转换中遇到了一些有趣的行为.
例1:
PS C:\Users\Nikhil\Documents> [string[]](Get-ChildItem .\GitHub\)
toc
toc-gh-pages
Publish gh-pages.txt
Run Code Online (Sandbox Code Playgroud)
例2:
PS C:\Users\Nikhil\Documents> [string[]](Get-ChildItem .\GitHub\*)
C:\Users\Nikhil\Documents\GitHub\toc
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages
C:\Users\Nikhil\Documents\GitHub\Publish gh-pages.txt
Run Code Online (Sandbox Code Playgroud)
示例3 :(使用-Recurse,因此转换为字符串是不合逻辑且无用的)
PS C:\Users\Nikhil\Documents\GitHub> [string[]](Get-ChildItem .\toc-gh-pages -Recurse)
assets
css
lib
_layouts
_site
.gitattributes
.gitignore
index.html
_config.yml
jquery.toc.zip
docs.less
docs.min.css
google-code-prettify
jquery.toc
lang-apollo.js
...
Run Code Online (Sandbox Code Playgroud)
例4:
PS C:\Users\Nikhil\Documents\GitHub> [string[]](Get-ChildItem .\toc-gh-pages\*.* -Recurse)
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\assets\jquery.toc.zip
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\css\docs.less
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\css\docs.min.css
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-apollo.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-basic.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-clj.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-css.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-dart.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-erlang.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-go.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-hs.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-lisp.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-llvm.js
C:\Users\Nikhil\Documents\GitHub\toc-gh-pages\lib\google-code-prettify\lang-lua.js
...
Run Code Online (Sandbox Code Playgroud)
在路径中添加通配符会导致生成的字符串成为完整路径名,而不仅仅是文件/文件夹名.为什么会这样?
我理解如何解决这种行为并获得我需要的信息; 我感兴趣的是,为什么发生这种情况,因为我们只是转换System.IO.FileInfo并System.IO.DirectoryInfo在所有情况下对象的字符串.
所以我有几个压缩文件,以及未压缩的版本.我最初没有创建这些文件的软件.我正在试图弄清楚底层算法是什么 - 你能搞清楚吗?最初,我认为它可能是一些LZW变种,但我不确定.当分解成6位字时,数据似乎更有意义 - 我看到很多重复模式.
这两个文件非常相似,未压缩的版本只有几个字节 - 这可以帮助确定压缩文件中这些不同字节的位置.我突出了这些差异.
压缩文件#1:
02 02 01 17 0E 11 92 14 C0 55 52 44 FF BC AE 47 DB E1 05 42 F8 70 DE 57 23 FF 54 1A 55 3D BF 54 10 E3 38 0C B2 FB C4 92 1C 20 DE 57 23 FF 54 1A 55 3D BE 5E 4C 96 B2 0E 32 80 CB 2F BC 48 70 83 79 5C 8F FD 50 …
我正在尝试使用 PowerShell 作为来自 IIS Express 的 CGI 二进制文件。我让它工作了,但是有一个我不太喜欢的愚蠢的解决方法。我想了解为什么需要这种变通方法。
这cgi.ps1是我用来尝试的一个简单文件:
"HTTP/1.1 200 OK`r`nContent-Type: text/plain`r`n`r`n"
Get-ChildItem env:
Run Code Online (Sandbox Code Playgroud)
连同这个web.config文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="PowerShell CGI" path="*.cgi" verb="GET,HEAD,POST" modules="CgiModule" scriptProcessor=""%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File C:\Users\Nikhil\Documents\GitHub\PowerShellCGI\App\cgi.ps1"/>
</handlers>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后,在此目录中启动 IIS Express 并导航到 后http://localhost:8080/hello.cgi,出现错误:
HTTP 错误 502.2 - Bad Gateway
指定的 CGI 应用程序因未返回一组完整的 HTTP 标头而行为不端。它确实返回的标题是“”。
我查看了Process Monitor,实际上 powershell.exe 确实以正确的参数启动。IIS Express 跟踪日志文件显示退出代码为 0,但输出流中没有任何内容。奇怪的是,当从 IIS Express 启动时,powershell.exe 甚至从未读取我的 ps1 文件;如果在使用 Process Monitor 捕获事件时手动使用相同的命令行,我可以看到正在读取的文件。
接下来,我尝试查看是否可以将普通的 …