Sublime Forum

Build .bat file, no output?

#1

Hi,

I’m trying to use a .bat file for a build process. In this case for Purebasic.

The cmd in the sublime-build file looks like this:
“cmd”: ["$packages\User\Builds\purebasic_build.bat", “$file”]

And the purebasic_build.bat file has some echo statements (e.g. which file
is build, etc.)

Don’t get me wrong, the sublime-build file is ok, and the .bat file is as well
-> The .pb file is build correctly (into an .exe file)

But I don’t get any output of the .bat file in the lower part of Sublime Text?

I’m using Build 3131 on Windows if that matters…

0 Likes

#2

Try shell_cmd instead of cmd

0 Likes

#3

Thanks but this isn’t working here…

"shell_cmd": ["$packages\\User\\Builds\\purebasic_build.bat", "$file"]

Trying to compile a .pb file leads to:
Traceback (most recent call last):
File “D:\Tools\Sublime Text\sublime_plugin.py”, line 795, in run_
return self.run(**args)
File “exec in D:\Tools\Sublime Text\Packages\Default.sublime-package”, line 238, in run
TypeError: Can’t convert ‘list’ object to str implicitly

in the Sublime Text console

Using only “cmd” shows at least the finished message:
[Finished in 0.5s]

0 Likes

#4

Oh yes you also need to use a string

"shell_cmd": "$packages\\User\\Builds\\purebasic_build.bat $file"
0 Likes

#5

Thanks, now the error message makes sense :slight_smile:

Unfortunately, I still get no output from the .bat file in the build console, only:

[Finished in 0.0s with exit code 1]
[shell_cmd: D:\Tools\Sublime Text\Data\Packages\User\Builds\purebasic_build.bat D:\Users\Highend\Dokumente\Development\PureBasic@Snippets@Procedures\Replace in file.pb]
[dir: D:\Users\Highend\Dokumente\Development\PureBasic@Snippets@Procedures]
[path: …stripped path content…]

And let’s assume, apart from the compiler invocation in the .bat file, one of the first lines is
Echo Testing compilation…

I never get to see that output in ST…

0 Likes

#6

The output that you’re posting above is indicative of the command being properly executed (it’s not complaining that it can’t find it) but returning a failure back (exit code 1; 0 is success); If a build works you only see the [Finished in x.xs] after the generated output.

Are there any commands prior to the echo that you don’t see? Perhaps one of them is causing the entire thing to error out before it gets that far.

0 Likes

#7

That’s because I didn’t modify the .bat file to make sure that it works with how it is called now using the changed
shell_cmd variant…
D:\Tools\Sublime Text\Data\Packages\User\Builds\purebasic_build.bat D:\Users\Highend\Dokumente\Development\PureBasic@Snippets@Procedures\Replace in file.pb

Let’s try to make this a bit easier
Now the purebasic_build.bat
only contains a single line
Echo testing…

Now the Build Result pane shows:
[Finished in 0.0s]

But that’s all.

No “testing” output from the .bat file
and it’s a necessity to be able to show what the .bat file outputs, e.g.
for compiler errors…

0 Likes

#8

If you have spaces in the file name you can try this:

"shell_cmd": "$packages\\User\\Builds\\purebasic_build.bat \"$file\""

Otherwise you may try to rename the fiel such that it does not contains spaces.

0 Likes

#9

Just for comparison purposes, I downloaded the portable version of Sublime 3131 and dropped it on one of my Windows machines to test with.

PureBasic.sublime-build

{
    "shell_cmd": "\"$packages\\User\\Builds\\purebasic_build.bat\" \"$file\""
}

Packages/User/Builds/purebasic_build.bat

@echo off
echo I am a batch file
echo my first argument is %1

With this in place, I selected Tools > Build System > PureBasic , put the cursor into the view for purebasic_build.bat, and got this output:

I am a batch file
my first argument is "C:\Users\tmartin\Desktop\Sublime_3131\Data\Packages\User\Builds\purebasic_build.bat"
[Finished in 0.1s]

The following build system also works identically for me:

{
    "cmd": ["$packages\\User\\Builds\\purebasic_build.bat", "$file"]
}

Something to keep in mind is that with cmd, you’re passing an array of distinct string arguments, whereas with shell_cmd you’re providing a string and requiring the shell to split the arguments apart itself.

This means that not only do you need to wrap your $file in double quotes (or more specifically \" to make the JSON in the build valid) in case the file you’re operating with is in a path that contains spaces, you also need to do so for the path to the batch file that you’re running if it has spaces. Above your output indicates that you have Sublime installed in a path with spaces in its name.

If this doesn’t work for you, I would suspect that it’s perhaps not using the build system that you think it’s using or possibly there is some package or modification interfering with things somehow, such as an override on Default/exec.py or some such.

To verify that everything is working as expected, after you run the build you can check the console with View > Show Console and see what Sublime says it tried to execute. For my example above, I see this:

Running C:\Users\tmartin\Desktop\Sublime_3131\Data\Packages\User\Builds\purebasic_build.bat C:\Users\tmartin\Desktop\Sublime_3131\Data\Packages\User\Builds\purebasic_build.bat
1 Like

#10

Thanks again!

It seems I’ve found the issue. The .bat file got saved with UTF-8 with BOM and
then you won’t see any output in ST’s build pane… Don’t know how this
happened…

Saving it with UTF-8 without BOM or Windows 1252 -> Output is there

1 Like

#11

Glad you got the problem sorted out! I never would have thought of an encoding issue like that being the cause for something like that; good to know for the future. :slight_smile:

0 Likes