Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让F脚本文件和其他脚本语言在Windows中像.exe、.cmd和.bat文件一样工作_Windows_Shell_Batch File_Explorer_F# Interactive - Fatal编程技术网

如何让F脚本文件和其他脚本语言在Windows中像.exe、.cmd和.bat文件一样工作

如何让F脚本文件和其他脚本语言在Windows中像.exe、.cmd和.bat文件一样工作,windows,shell,batch-file,explorer,f#-interactive,Windows,Shell,Batch File,Explorer,F# Interactive,可以配置F脚本文件,以便在不直接指定脚本运行程序应用程序及其文件扩展名的情况下直接调用这些文件,并且可以通过命令路径环境变量访问这些文件 操作步骤如下: open System let args = Environment.GetCommandLineArgs() |> Seq.skipWhile (fun p -> p <> "--") |> Seq.skip 1 |> List.ofSeq 使用Windows资源管理器将特定

可以配置F脚本文件,以便在不直接指定脚本运行程序应用程序及其文件扩展名的情况下直接调用这些文件,并且可以通过命令路径环境变量访问这些文件

操作步骤如下:

open System

let args = 
   Environment.GetCommandLineArgs()
   |> Seq.skipWhile (fun p -> p <> "--") 
   |> Seq.skip 1
   |> List.ofSeq
使用Windows资源管理器将特定脚本引擎设置为脚本文件类型扩展名的默认“打开方式”程序 将脚本扩展附加到PathExt环境变量,该变量将其分类为可执行文件 (可选)包括包含脚本到Windows路径环境变量的目录路径

我的问题:当你没有直接调用它的Runter应用程序时,如何得到脚本的参数。

< P>下面提供了一个简单的技术,用于配置Windows系统以将F作为与CMD和批处理文件相媲美的脚本语言。因此,脚本可以从环境路径访问,不需要文件类型扩展名就可以调用,并且可以传递任意数量的参数。此技术应适用于其他脚本语言,如powershell、python等

以下是用于在.Net 4.0中为F 3.1建立此配置的批处理文件:

configure.bat
  rem absolute filename of the F# script runner, Fsi.exe
  set fsharpScriptRunner="C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Fsi.exe"

  rem script runner command for fsi.exe to execute script and exit without advertising itself
  set fsharpScriptRunnerCmd=%fsharpScriptRunner% --nologo --exec 

  rem associate "FSharpScript" files with fsharpScriptRunnerCmd, appending
  rem the file name and remaining line arguments into the commandline
  rem after the delimiter "--"
  ftype FSharpScript=%fsharpScriptRunnerCmd% %%1 "--" %%*

  rem associate file extension ".fsx" with the file type "FSharpScript"
  assoc .fsx=FSharpScript

  rem add ".fsx" to the list of file types treated as executable
  set pathext=%pathext%;.fsx
请注意,ftype命令行中的-用作分隔符,以帮助脚本区分其命令行参数与脚本运行程序的参数;F脚本接收所有参数,并且必须解析出它的参数。我使用提供的分隔符进行的笨拙的F版本解析如下所示:

open System

let args = 
   Environment.GetCommandLineArgs()
   |> Seq.skipWhile (fun p -> p <> "--") 
   |> Seq.skip 1
   |> List.ofSeq

享受。

打开提升的命令提示符,并创建文件类型:ftype fsxfile=path\to\fsi.exe%1%*。将此类型与文件扩展名关联:assoc.fsx=fsxfile。@eryksun感谢您提供有关assoc,ftype的信息。然而,在应用它们之后,问题仍然存在。似乎您建议的从命令行应用的设置实际上并没有替换windows资源管理器中的设置。但是,更改由assoc和ftype查询选项报告。尽管如此,该行为仍然是以前由explorer设置的。如果您有任何其他见解,那将非常好。ftype和assoc在注册表项HKLM\SOFTWARE\Classes下修改本地计算机设置。当前用户的设置优先;它们属于HKCU\软件\类。此外,浏览器在HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts下有自己的文件关联,但您应该能够通过GUI管理这些关联,以选择使用cmd的ftype命令创建的文件类型。@eryksun再次感谢。我的注册表似乎没有按预期运行。sfc/scannow报告无法修复某些问题。我的系统的性能最近相当差,所以我正在为系统重新初始化、软件重新安装以及随之而来的被忽视的东西的wtf做准备。如果您有任何建议,我欢迎您的建议。如果您对系统文件检查器sfc和/或损坏的注册表有具体问题,我建议您继续提问。