本文介绍了命令提示:从任何文本文件执行命令(不具有" .BAT"或QUOT; .CMD"扩展)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我找不到任何办法的事,例如,以下内容:

I can't find any way to do, for example, the following:

的cmd.exe / cscript.txt

在换句话说,我需要命令提示符(尝试)与任何扩展执行文件(不一定的.bat 的.cmd )是否包含有效的批处理脚本code。我在寻找类似Unix外壳行为:

In other words, I need Command Prompt to (try) to execute file with any extension (not necessarily .bat or .cmd) if it contains valid batch script code. I'm looking for behavior similar to Unix shells:

./ script.txt

在Unix上的家当的(#!/ bin / sh的)负责理解该文件实际上是一个脚本,它似乎就像在Windows 的.bat 的.cmd 扩展起到同样的作用,指示命令提示符批处理脚本文件。

While on Unix the shebang (#!/bin/sh) is responsible for understanding that the file is actually a script, it seems like on Windows .bat or .cmd extensions play the same role, indicating a batch script file for Command Prompt.

是否有可能避免和强迫命令提示符间preT文件与任何名称?

Is it possible to avoid that and force Command Prompt to interpret a file with any name?

注意:请,不一样的答案:

给你的文件的.bat 的.cmd 扩展。

这不是问题是什么。

推荐答案

您首先需要一个安装脚本:

you first need an "installation" script :

   @echo off

    rem :: A files with .TEST extension will be able to execute batch code but is not perfect as the %0 argument is lost

    rem :: "installing" a caller.
    if not exist "c:\caller.bat" (
       echo @echo off
       echo copy "%%~nx1"  "%%temp%%\%%~nx1.bat" /Y ^>nul
       echo "%%temp%%\%%~nx1.bat"  %%*
    ) > c:\caller.bat

    rem :: associating file extension
    assoc .test=batps
    ftype batps=c:\caller "%%1" %*

然后尝试一个简单的 .TEST 文件:

@echo off
for /l (1;1;10) do (
  echo testing .TEST extension
)

在事实上 ASSOC FTYPE 都具有立竿见影的效果,所以你可以开始。测试文件上右键安装之后。与注册管理机构直接编辑最终你可以得到更多的控制 - > How创建行为类似的.cmd / .BAT?的文件扩展名。检查还降处理器 - >的

In fact ASSOC and FTYPE both have immediate effect so you can start a .test file right after "installation". With direct editing of the registry eventually you can get more control -> How to create file extension that behaves as .cmd/.bat? . Check also drop handlers -> http://msdn.microsoft.com/en-us/library/windows/desktop/cc144165%28v=vs.85%29.aspx

这篇关于命令提示:从任何文本文件执行命令(不具有" .BAT"或QUOT; .CMD"扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:50