1

There are no problems while building, and a message at the bottom line says "Building finished"...but when I try to run it, this message appears:

[Error 2] The system cannot find the file specified
[cmd:  [u'bash', u'-c', u"g++ 'D:\\Apps\\hello.c' -o 'D:\\Apps/hello' && 'D:\\Apps/hello'"]]
[dir:  D:\Apps]
[path: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\Calibre2\;C:\Program Files (x86)\Vodafone\Vodafone Mobile Broadband\Optimization Client\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\CodeBlocks\MinGW\bin\;D:\Apps]
[Finished]

and I'm still new to Sublime Text 2.

6
  • what does the windows equivalent of ls -lR D:\Apps give you? I just noticed that the bash command is operating on D:\Apps/hello, not D:\Apps\hello as it should be. Could it be that simple?
    – mfabel
    Dec 2, 2013 at 7:00
  • Please post your build file.
    – AGS
    Dec 2, 2013 at 14:37
  • @AGS - this is the default C++.sublime-build that comes with ST2. I don't know why there's a bash command in there. It's fixed in ST3.
    – MattDMo
    Dec 3, 2013 at 1:38
  • @MattDMo yes, when I tried ST3 it worked.
    – ManaOttman
    Dec 3, 2013 at 7:03
  • @AGS I'm sorry the problem is fixed and the old build file is overwritten.
    – ManaOttman
    Dec 3, 2013 at 7:06

1 Answer 1

2

Create a new file in Sublime with the following content:

{
    "cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],

    "variants": [

        {   
            "cmd": ["start", "cmd", "/k", "$file_base_name"],
            "shell": true,
            "name": "Run"
        }
    ]
}

On the 2nd line, change the name of mingw32-g++.exe to whatever g++ is on your system - possibly just g++.exe. Save the file in the User subdirectory of your Packages folder (which should be in %APPDATA%\Sublime Text 2) as new_g++.sublime-build. When you select this build system as your default (Tools -> Build System -> new_g++), hitting CtrlB will compile your program, and then hitting CtrlShiftB will execute it. start is the command to start running a separate process, cmd is short for cmd.exe, the Windows command line program, and the /k option keeps the resulting window open after your program exits so you can see its output, run additional commands, or what have you.

5
  • Thanks, I wanted to vote this answer up but I still don't have enough reputation points.
    – ManaOttman
    Dec 3, 2013 at 7:10
  • I think that ST is great but it disappointed me today with another problem,as I wrote a very simple c code with a scanf function embedded into it..to see how ST handles user inputs but disappointingly it seems that ST doesn't support user inputs. any suggestions for this problem!.
    – ManaOttman
    Dec 3, 2013 at 7:18
  • @ManaOttman - if my answer helped you, just click on the check mark next to it. It will mark your question as answered, and will help future visitors who may have a similar problem.
    – MattDMo
    Dec 3, 2013 at 7:40
  • @ManaOttman - in regards to your second comment, unfortunately neither version of Sublime directly supports user input, whether it's scanf in C, raw_input() in Python, gets in Ruby, or any other language. For interpreted languages, you can use SublimeREPL, and for compiled ones the build system I suggested in my answer will work just fine through cmd.exe.
    – MattDMo
    Dec 3, 2013 at 7:43
  • Actually, technically that isn't completely true, there are ways for plugins to interact with users via the Python API, but direct input is not supported.
    – MattDMo
    Dec 3, 2013 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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