简体   繁体   中英

Calling batch file from original cmd works, but from .bat files doesn't

-BASIC INFORMATION I have this sourceforge project called E-Series which makes certain coding tasks more easier, in this question I'll specifically be talking about "Easy Command Line" from E-Series.

-NOTES

-Once again, In the title as well, calling the batch file from original cmd (Access it by going to Run>cmd) does work, however calling it from a .bat file designed to call it does not.

-the batch file i'm calling has parameters.

-WHAT I'VE GOT

HERE are all the files required to run the whole program (download it if you want more specific information); note that when trying to type in my custom commands (Which you can see by typing help) such as "newfolder (name)" or "newfile (name and extension)" fails but calling it from cmd works. Just open command.bat for cmd if you downloaded it.

-WHAT I NEED

I need a .bat file that can "properly" call a batch file WITH parameters.

-WHERE DOES IT HAPPEN -CALLING BATCH FILE FROM .bat file

I seriously recommend you download my program before going here, Or else it PROBABLY will not make ANY sense to you.

I have supposedly found out where the error happens;

@echo off
title Easy Command Line 0.1 E-Alpha
color a
:: The script is completely formatted in NotePad++ I recommend you use that when you're viewing the
:: Source code :)
:: This program is in extreme alpha say... 0.1 Alpha (Versions are counted every tenth (0.1),) 
goto function_system_checkall
%clearcommand%
echo CONSOLE : Easy Command Line
echo CONSOLE : Type in "help" for a list of available commands. To enter batch mode
echo CONSOLE : type 'batchcommand'
:reset
set /p ecl_command="INPUT %cd%: "
if %ecl_command% == help goto help
if %ecl_command% == when echo %time%, %date%
if %ecl_command% == settings goto settings
if %ecl_command% == clear cls&goto reset
if %ecl_command% == clearscreen cls&goto reset
if %ecl_command% == cls cls&goto reset
if %ecl_command% == ping goto function_notyet
if %ecl_command% == checkall goto function_system_checkall
if %ecl_command% == navigate goto function_navigate
if %ecl_command% == debug @echo on
if %ecl_command% == disable_debug @echo off
call %ecl_command%

opening my program within debug mode (@echo on) shows that whenenver I type in "newfolder (name)" or "newfile (name & extension)" causes the output:

INPUT D:\Projects\easycommandline: newfolder 14
14 was unexpected at this time.

D:\Projects\easycommandline>if newfolder 14 == help goto help
ECL crashed!
Press any key to relaunch ECL. It is recommended to go into debug mode (type debug)

DETAILED SCREENSHOT 这里 Which makes no sense. What does It mean with 14 was unexpected at this time. ? The method with my command parsing is first, it checks if the input corresponds to certain in-batch file commands such as "clear, cls, list, when, help" but in the very end, There's a "call" function because external programs are designed to handle directory (and more) actions such as creating a new folder, new file, etc.

-Calling batch file from cmd

As I've said, calling the batch file from CMD is FLAWLESS; 在此处输入图片说明

How can i fix this? getting really frustrated :( tell me if you need EVEN MORE information

In places where spaces can be included or a & character then you need double quotes:

Not this:

if %ecl_command% == help goto help

but this, and in all similar lines:

if /i "%ecl_command%" == "help" goto help

The /i makes the compare case insensitive.

Check encoding of your .bat file. When I used UTF-8, command prompt displayed error:

C:\Users\***\Desktop>´╗┐cmd
'´╗┐cmd' is not recognized as an internal or external command,
operable program or batch file.

When I used ANSI encoding, the .bat file worked as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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