0

I want to build a file using Sublime Text 2, and then do a simple copy. I managed to do the first thing using a build system, and I think it has to be possible to do the copy with the build system also (because I can do it in a batch file).

The batch script what does what I want to do is:

copy /b hang.bin+sectors.bin image.img

And the build system that I use is:

{
"cmd": ["copy", "/b", "hang.bin+sectors.bin", "image.img"],
"working_dir": "$file_path"
}

The error message that I get:

[Error 2] The system can't find the specified file
[cmd:  [u'copy', u'/b', u'hang.bin+sectors.bin', u'image.img']]
[dir:  C:\Documents and Settings\xxx\Desktop\Project]
[path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Ulead Systems\MPEG]
[Finished]

Yeah, I hardcoded the hang.bin file to see if that would work, but no. Normally I would use ${file_name}.bin there.

I suspect the + syntax of the two files that are to be copied (to one new file) is the problem, but I'm not sure. Can anybody help me?

1

Run where copy in a command line and you'll see that copy isn't a program, but a built-in command provided by cmd. Sublime Text runs build systems natively, without cmd, so it doesn't recognize copy.

There's a workaround: execute the command through cmd.  From cmd's help (see this or this):

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates

So, for example, cmd /C notepad will execute Notepad and exit immediately, without waiting for it to exit. cmd /C copy will work too, because it's executed through cmd. Your command should look like this:

cmd /C "copy /b hang.bin+sectors.bin image.img"

Remember about the quotes, otherwise /b and the rest of the command will be treated as arguments for cmd, not copy.

6
  • Thanks! What would the sublime-build-form of that be? I tried a lot of things, but I can't get it to work... – Ruben Aug 15 '13 at 19:23
  • What exactly have you tried? The last codeblock should be working, but remember about escaping quotes etc. – gronostaj Aug 15 '13 at 22:08
  • I tried converting that to JSON format by trying things like { "cmd": ["C:\\nasm\\nasm", "$file_name", "-f bin", "-o hang.bin"], "cmd": ["cmd /C \"copy /b hang.bin+sectors.bin image.img\""], "working_dir": "$file_path" } but that gives me the same error as before (error 2: the system can't find the file specified). If I just copy the line, I get the message "Error trying to parse build system: Expected value in <path>/build.sublime-build:1:1" – Ruben Aug 17 '13 at 11:46
  • 1. You can't have two fields with identical names in a JSON (I'm looking at cmd). If you want to issue more than one command, the simpliest way to achieve it is to create a batch file and start it from a build system. You can pass as many arguments as you wish and then issue your commands from that BAT file. 2. In build system paths you should use slashes, not backslashes - Sublime Text will take care of them and you'll avoid escaping problems. 3. I remeber that I once had to use double escaping, i.e. instead of " it should be \\\". You can try that. – gronostaj Aug 17 '13 at 15:13
  • Clear! It worked out. My sublime build file: { "cmd": ["<path>/assemble.bat", "$file_name"], "working_dir": "$file_path" } My assemble.bat file: C:\\nasm\\nasm %1 -f bin -o boot.bin bfi -f=boot.img -l=bootflop ./floppy bootcopy (As you can see, I don't use copy anymore, but a tool I wrote myself called bootcopy) – Ruben Aug 18 '13 at 9:42
0

This worked for me:


It works with paths and files with whitespaces by spilting up the arguments with "arg" , such as:

[..., "/C", "START", "${file_path}", "${file_name}"]


Paste this into your Batch.sublime-build file.

{
    "file_patterns": ["*.bat"],
    "selector": "source.Batch",
    // This runs the batch file in cmds' console
    "cmd": ["cmd", "/C", "START", "${file_path}", "${file_name}"]
}

Your batch file can then be run in the CMDs' CLI. I suppose it's possible to pass arguments also but this may be a starting point for you.

The above will run cmd.exe and run the code in its native console. This will accept your inputs of the .bat file.


Here's a build that can be saved as BatchStConsole.sublime-build

{
    "file_patterns": ["*.bat"],
    "selector": "source.Batch",
    // This outputs to Sublime Texts' console
    "cmd": ["cmd", "/C", "${file}"]
}

The above will run the code in Sublime Texts' console. This will not accept your inputs of the .bat file. But still useful for debugging as it passes any arguments like the native CLI but just no interaction.


Relevant help:

START https://ss64.com/nt/start.html

http://docs.sublimetext.info/en/latest/reference/build_systems/configuration.html#platform-specific-options

https://www.sublimetext.com/docs/3/build_systems.html

7
  • (1) The OP seems to be trying to get away from having a batch file.  (2) Why do you throw a START command into this? – Scott May 16 '19 at 5:52
  • (1) He quotes: Normally I would use ${file_name}.bin there. so I assumed he wanted what I've shown (2) Because it'll only output to the ST console otherwise. I've shown two examples in the post. But I suppose: "cmd": ["C:\\\\Windows\\System32\\cmd", "START /c $file"] could be shortened to "cmd": ["C:\\\\Windows\\System32\\cmd.exe", "/c $file"] but it doesn't affect the result. See this for help on START link. – Ste May 16 '19 at 10:29
  • (1) If you believe that people who read your answer might want to know more about the START command, you’re probably right, and it makes sense to include the link to the ss64.com page in your answer.  I’m already familiar with the command, so telling it to me isn’t as useful.  (2) You suppose cmd […, "START /c $file"] could be shortened to cmd […, "/c $file"].  Therein lies the point of my question: why add an extra command word if it doesn’t affect the result?  (2½) I see that you’ve edited your answer to remove the START /c, which is an invalid command, … (Cont’d) – Scott May 16 '19 at 19:04
  • (Cont’d) …  and changed "/c $file" to "/C", "${file}".  (3) But doesn’t it affect the result?  I don’t use Sublime Text, and I’m not familiar with this “build system” stuff, but, when I use START from a Command Prompt window, it creates a new window.  (3½) I see now that you seem to acknowledge that difference.  I overlooked it because you used the word “console” rather than “window”.  (4) I see that you’ve removed the full path from your answer, but, for future reference, I doubt that you need quadruple backslashes after C:. … (Cont’d) – Scott May 16 '19 at 19:04
  • (Cont’d) …  (5) I see that you’ve removed it from your answer, but I’m curious what you think a & means at the end of a CMD command.  (6) Thank you for bringing up file names and paths with whitespace;  I was going to mention it if you hadn’t.  Pursuant to that, you might want to explain why your answer says "START", "${file_path}", "${file_name}" (i.e., why file_path and file_name?).  Don’t explain it to me; I understand it.  Put it into the answer.  (7) Why do you have "${file_name}" in one case and "${file}" in the other? – Scott May 16 '19 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.