Simple Batch File "Input Error"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Simple Batch File "Input Error"

#1 Post by JoeNoName » 06 Jan 2014 19:34

New to the site, just want to say thanks in advance.

As part of a larger batch file that involves creating a directory with today's date, copying and pasting files to be backed up, changing privileges and deleting files older then X days, I've run into a problem. This is where I run into my problem:

Code: Select all

echo var D = new Date() > tmp.js
echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> tmp.js
echo WScript.Echo( 'set YYYYMMDD='+D ) >> tmp.js
echo @echo off > tmp.bat
cscript //nologo tmp.js >> tmp.bat
call tmp.bat


The weird thing is this runs fine on one machine on the network but fails on another. After that last line the command prompt spits back an error that looks like this:

Input Error: There is no file extension in "C:\Users\name\Desktop\Error: ".

Any help would be greatly appreciated.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#2 Post by foxidrive » 06 Jan 2014 20:03

Have a look and see what is inside tmp.bat


If it looks ok then the error is somewhere else in your script.

JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Re: Simple Batch File "Input Error"

#3 Post by JoeNoName » 06 Jan 2014 20:47

I don't have access to the computer that is giving me the error right now, but will check first thing in the morning. The error is definitely coming from that part of the script. I suspect the error has something to do with that computer because the script works perfectly on two other machines. Something not updated or not installed maybe, I really have no idea where to look though.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#4 Post by foxidrive » 06 Jan 2014 20:55

Maybe Windows Scripting Host is disabled, or write access is denied in the folder.

Put a pause before and after the cscript line and see if there are any error messages on the console.

There's nothing there that would give that particular error message, that I can think of.

JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Re: Simple Batch File "Input Error"

#5 Post by JoeNoName » 06 Jan 2014 21:23

Pretty sure I have write access because I can see the tmp.bat and tmp.js being created in the folder when i run the script. I did put a pause in the script though, that's how I found the error. Otherwise the batch file started and closed without any indication that it failed.

This is specifically what I saw in the command prompt with the pause in it (i printed it out)
From the last line of the script I quoted earlier:

Code: Select all

C:\Users\name\Desktop>call tmp.bat
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Input Error: There is no file extension in "C:\Users\name\Desktop\Error:".


Thanks again for your help, I'm stuck.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#6 Post by foxidrive » 06 Jan 2014 21:49

I can't see the pause statement so the error could be anywhere in the batch file after cscript.
In fact that is not the same batch file running - cscript has the /nologo switch and that is showing the logo.

Put a pause above and below the cscript line.

Copy and paste the console screen in a reply, or post a screenshot. Copy the contents of tmp.bat too.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#7 Post by foxidrive » 06 Jan 2014 21:53

Hang on - are you calling your batch file tmp.bat ?
tmp.bat is the temporary batch file name also.

But something is very wrong because your console shows the call tmp.bat is executing *before* the cscript logo appears.

Please show us the actual code.

JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Re: Simple Batch File "Input Error"

#8 Post by JoeNoName » 06 Jan 2014 22:08

Okay, so the batch file is NOT called tmp.bat it is called Backup.bat. The tmp.bat is temporary and is deleted and the end of the batch file. I think the order of operations is okay too, since i'm putting the cscript command into the tmp.bat file. Per my original post:
cscript //nologo tmp.js >> tmp.bat


Like I said I don't have access to the machine that is giving me the error right now, but will update this thread with screenshots of the console in the morning.

What I posted is the actual code, that is as far as the file made it before i hit this error. After the first failed attempt, I commented out the rest of the batch file to concentrate on this part.

This part of the code is used to format the date to my liking and is then used to:

Code: Select all

mkdir \\blah\blah\%YYYYMMDD%


I hope you understand what I'm saying. And again I REALLY appreciate your help, I know this is frustrating.

Atleast that's what it's supposed to do when it works.

I think the error I'm getting is coming from the tmp.js file because it's being put INTO the tmp.bat file. Somewhere the communication between those two files is creating an error but I'm not sure why.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#9 Post by foxidrive » 06 Jan 2014 22:18

JoeNoName wrote:This is specifically what I saw in the command prompt with the pause in it (i printed it out)
From the last line of the script I quoted earlier:

Code: Select all

C:\Users\name\Desktop>call tmp.bat
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Input Error: There is no file extension in "C:\Users\name\Desktop\Error:".



A) why is call tmp.bat appearing before the cscript logo.
B) why is the cscript logo appearing when it has a switch to disable the logo?

JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Re: Simple Batch File "Input Error"

#10 Post by JoeNoName » 06 Jan 2014 22:34

A) call tmp.bat is appearing before the cscript logo because Calling tmp.bat is what runs the cscript command. The line:

Code: Select all

cscript //nologo tmp.js >> tmp.bat

doesn't actually run the cscript command it puts into into tmp.bat

B) This is part of what I'm trying to find out. Because Calling tmp.bat is delivering odd results I think there is something wrong with tmp.js or the cscript command.

I have actually been able to recreate a similar (but different) error by entering this directly into the command prompt:
@cmd prompt

Code: Select all

cd C:\Users\blah\Desktop\
cscript //nologo tmp.js >> tmp.bat
call tmp.bat


If you enter those, in that order, you will get an Input Error because tmp.js doesn't really exist. It does seem, however, to suppress the cscript logo.

Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Batch File "Input Error"

#11 Post by foxidrive » 07 Jan 2014 03:54

JoeNoName wrote:A) call tmp.bat is appearing before the cscript logo because Calling tmp.bat is what runs the cscript command. The line:

Code: Select all

cscript //nologo tmp.js >> tmp.bat

doesn't actually run the cscript command it puts into into tmp.bat


You are mistaken. Cscript runs the .js script, and the output from the script is redirected into the batch file.

After that happens then tmp.bat is called. Your screen info shows tmp.bat running first.

Seeing the layout of the screen you showed us, I can be certain that it is not the same code that you also showed us.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Simple Batch File "Input Error"

#12 Post by penpen » 07 Jan 2014 04:05

I'm pretty sure you have placed the pause, you mentioned above, somewhere after that "call tmp.bat", but not in its following line.
Then you saw the above output, which leads to your conclusion that the "call tmp.bat" pushes the error.

If i'm right, then please rem this line out:

Code: Select all

echo @echo off > tmp.bat
Then there should be displayed some additional lines processed.

penpen

Edit: If i'm wrong please verify the output of tmp.js, and tmp.bat via:

Code: Select all

@echo ==================
@echo :: tmp.js
@type tmp.js
@echo ==================
@echo :: tmp.bat
@type tmp.bat
@echo ==================

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple Batch File "Input Error"

#13 Post by Squashman » 07 Jan 2014 08:41

Sometimes you just need to post all the code so that we can help you. Showing just a code snippet usually just causes most of us to speculate what the problem is. If we can recreate the entire script on our end it is a lot easier to troubleshoot.

JoeNoName
Posts: 12
Joined: 06 Jan 2014 18:57

Re: Simple Batch File "Input Error"

#14 Post by JoeNoName » 07 Jan 2014 09:43

The code that is returning an error in it's entirety:

Code: Select all

echo var D = new Date() > tmp.js
echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> tmp.js
echo WScript.Echo( 'set YYYYMMDD='+D ) >> tmp.js
echo @echo off > tmp.bat
cscript //nologo tmp.js >> tmp.bat
call tmp.bat
mkdir "\\location\file\%YYYYMMDD%"
PAUSE
del tmp.js
del tmp.bat


@foxidrive: I understand what you are saying but the results of running the cscript command are put into the tmp.bat file whether it's with the logo or //nologo. You can test this at the command prompt:

Code: Select all

cscript >> tmp.bat


The line above should give you the cscript logo since you didn't add the option //nologo. It won't show in the command prompt though unless you call tmp.bat.

The code is the same as we discussed last night. Please see above I've posted the code in it's entirety.


@penpen: Thanks for your help. I posted the code above. I am going to check the contents of tmp.js and tmp.bat at lunch. I'm fairly certain the problem is in the javascript file.


@Squashman: I understand what you are saying but I have entered the entire code that is giving me the error above. When i first ran the batch file I started to remove segments of the original code until i narrowed down the problem. Running the batch file I posted above returns the exact error I posted.


Thank you again, everyone, for your help.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple Batch File "Input Error"

#15 Post by Squashman » 07 Jan 2014 11:32

So your batch file went from 6 lines to 10 lines. What is the big deal with just posting the entire code in the first place?

Post Reply