简体   繁体   English

无法使用* .bat文件启动* .exe,但是如果直接从CMD运行命令,它将启动

[英]Cant start *.exe with *.bat file, yet it will start if command is run from CMD directly

I have a script that closes a process called ncat.exe and then reopens it, or at least that's what I want it to do, but it doesn't seem to be working when I run the .bat file. 我有一个脚本关闭一个名为ncat.exe的进程,然后重新打开它,或者至少是我想要它执行的操作,但是当我运行.bat文件时,它似乎无法正常工作。 Here is part of the script: 这是脚本的一部分:

TASKKILL /F /IM ncat.exe* /T >nul 2>nul
ping localhost -n 3 >nul
regedit /S c:\ncatprintingPuttyDefaults.reg
cd c:\
ncat_lpt1.exe
timeout /t 10 /nobreak >nul

These is not starting ncat_lpt1.exe which has inside this script: 这些不会启动此脚本中ncat_lpt1.exe

@ECHO OFF
cd c:\Program Files (x86)\Ncat
ncat.exe -l -k -p 5964 > lpt1

This is were it gets interesting, if I go to cmd and manually type 如果我转到cmd并手动键入,这是否变得有趣了

cd c:\
ncat_lpt1.exe

It runs right away no problem. 它立即运行没问题。 So if done through the bat file wont work but manually it will. 因此,如果通过bat文件完成操作,将无法正常工作,但是手动进行则可以。 Mind Blown pufff... 心灵吹泡泡...

Help? 救命? Let me know if need any other detail, I tried to explain best as I could :) 让我知道是否需要其他详细信息,我会尽力解释最好:)

TASKKILL /F /IM ncat.exe* /T >nul 2>nul
ping localhost -n 3 >nul
regedit /S c:\ncatprintingPuttyDefaults.reg
cd c:\
CALL ncat_lpt1.BAT
timeout /t 10 /nobreak >nul

Change the name of C:\\ncat_lpt1.exe to ncat_lpt1.bat C:\\ncat_lpt1.exe的名称更改为ncat_lpt1.bat

(from the prompt, ren C:\\ncat_lpt1.exe ncat_lpt1.bat ) (从提示符ren C:\\ncat_lpt1.exe ncat_lpt1.bat

@ECHO OFF
cd c:\Program Files (x86)\Ncat
ncat.exe -l -k -p 5964 > lpt1

Windows uses the extension to the filename to determine how to run the file. Windows使用文件名的扩展名来确定如何运行文件。 You can't simply name a batch file with an .exe extension to execute it - it needs a .bat extension. 您不能简单地命名一个扩展名为.exe的批处理文件来执行它-它需要一个.bat扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM