This works in Command prompt but not for a batch file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
noname91
Posts: 2
Joined: 15 Nov 2018 07:44

This works in Command prompt but not for a batch file?

#1 Post by noname91 » 15 Nov 2018 08:20

Hello to all,

I'm trying to create a batch file to run an automated process to export files as .pngs for the sprite editing tool Asesprite, but running into problems.

I have the following command in CP:

Code: Select all

G:\Desktop\Char_A>"G:\Desktop\Ase\Aseprite.exe" -b sp.aseprite --save-as output.png


This allows me to create .png files from the sp.aseprite file right into the Char_A folder. This works fine in CP. But for doing the same process using a batch file is proving to be difficult.

I tried the following initially:

Code: Select all

@ECHO OFF
 ECHO.
 START "G:\Desktop\Ase\Aseprite.exe" -b sp.aseprite --save-as output.png
 ECHO.
 PAUSE
 CLS
 EXIT 
But after saving that code in notepad and saving it as a .bat and running it from inside the Char_A folder, it gives me an error saying that the system could not find the file -b.

I also tried swapping START with FOR and inserting a DO before the -b, it acts like it executed, but does not create the output file.

Any guidance on how to make this work for a batch file would be greatly appreciated.

Please also note that the end result is to get this to work in a manner such that all .aseprite files in a folder are read and outputted with the same name, but as .pngs. I'm sure the FOR, DO and * functions will be used, but I'd have to get the basics down first before the actual problem can be addressed.

Thanks in advance.

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

Re: This works in Command prompt but not for a batch file?

#2 Post by Squashman » 15 Nov 2018 10:24

Technically you are not using the SAME CODE. You are now using the START command. The START command interprets the first set of quotes as the Window TITLE. So you need an empty set of quotes at the beginning.

Code: Select all

START "" "G:\Desktop\Ase\Aseprite.exe" -b sp.aseprite --save-as output.png

noname91
Posts: 2
Joined: 15 Nov 2018 07:44

Re: This works in Command prompt but not for a batch file?

#3 Post by noname91 » 15 Nov 2018 14:18

Thank you Squashman.

Your solution works great. I was a different pc before so I made some changes to the original. The new one looks like this:

Code: Select all

@ECHO OFF
 ECHO.
 START "" "C:\ase\aseprite.exe" -b walk.aseprite --save-as output.png
 ECHO.
 PAUSE
 CLS
 EXIT 

The above batch file will correctly create the .pngs for "walk.aseprite" and name them to output1.png, output2.png etc...

As stated in the op, the goal is to do this for all .aseprite files in the asset folder and have them named after the file from which the .pngs are derived. So walk.aseprite would create walk1.png, walk2.png while stand.aseprite would create stand1.png, stand2.png etc.

I did some research to try and find a solution for this and couldn't come up with anything better than the following:

Code: Select all

@ECHO OFF
 ECHO.
 SET aseprite="C:\ase\aseprite.exe" FOR %%file in C:\char_a\*.aseprite ; do "$aseprite" -b $file --save-as ${file%.aseprite}.png
 ECHO.
 PAUSE
 CLS
 EXIT
Though the batch runs without any errors, it doesn't create anything. Different combinations of commands in the beginning throws errors highlighting non-existant files, or an inability to detect the *.aseprite files correctly.

Once again, any guidance here would be greatly appreciated.

Thanks.

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

Re: This works in Command prompt but not for a batch file?

#4 Post by Squashman » 15 Nov 2018 22:25

Not sure where you got that code from but it is not even remotely close to any batch file code. It is probably closer to BASH.

Post Reply