Sublime Text won't output Java println statements in main method - sublimetext2

my Sublime Text javac build settings don't work for outputs like System.out.println statements in the main method.
I am using this sublime-build (javac):
{
"cmd": ["javac", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"working_dir": "${project_path:${file_path}}",
"variants": [
{
"name": "Run",
"cmd": ["java", "$file_name"],
"shell": true,
"env": {"CLASSPATH": "/path/to/jar/files:/path/to/more/jars"}
}
]
}
Changing "cmd" to
"cmd": ["javac \"$file_name\" && java \"$file_base_name\""]
won't work either. But it compiles correctly and has a correct output on my bash command line.
Any thoughts?
Thanks in advance!

Nevermind, I got it:
That's the magic line missing:
"cmd": ["sh", "-c", "javac $file_base_name.java && java $file_base_name"],

Related

How to fix "/bin/bash: [command] command not found" after setting up tasks.json and c_cpp_properties.json for C++ on Windows 10 VS Code?

I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press
Ctrl + Shift + B
As soon as I do a terminal pops up and alters me of an error:
Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:
g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
I also checked the path according to this figure
The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.
Here are my JSON files which are inside my .vscode file:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
I should expect to see a ".exe" after compiling but I can't due to the error.
After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.
According to the png image from above, I've included "C:\MinGW\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.

Errors when setting up Shell Launcher Extension for VSCode with Anaconda Prompt and Git Bash

I'm having trouble getting anaconda prompt to work with VSCode shell launcher.
Im trying to set up the Shell Launcher Extension for VSCode to run the following terminals on windows 10:
Git Bash,
CMD,
Powershell,
Anaconda Prompt
I have configured my settings. json with the following code:
{
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd",
"args": [],
"label": "cmd"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
},
{
"shell": "cmd",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
}
]
}
As you can see Bash is my default terminal that opens with ctrl+` and my shell launcher opens with ctrl+shift+t .
The Shell launcher lists my all of the entries above, and all terminals launch through Shell Launcher except Anaconda Prompt.
From what I understand according to this blog post: How to Add Anaconda Prompt to VSCode Integrated Terminal,
Anaconda Prompt extends windows cmd and I just need to pass in the Arguments that run the script.
I pulled the args out of the properties of Anaconda menu, but when I try to launch the anaconda prompt I get the following error message:
The terminal process command 'cmd /K 'C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3'' failed to launch (exit code: 2)
Here is the path from the properties menu of the anaconda prompt desktop icon that works normally.
%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
I have tried adding the actual path of cmd as:
%windir%\\System32\\cmd.exe
, but this just removes the Anaconda prompt from the Shell Launcher drop-down menu completely.
How can I fix this?
Any help will be appreciated. :)
I fixed it. "cmd.exe" was the path that worked.
For anyone else who want's to set up multiple integrated terminals in VScode for windows 10 here's the settings for the Shell Launcher extension that I am using.
This sets the my default terminal to Git Bash and allows me to open bash, cmd, Anaconda prompt and powershell with Shell Launcher.
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd.exe",
"args": [],
"label": "cmd"
},
{
"shell": "cmd.exe",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
}
]
Happy Hacking. ;)

Enter Input to sublime text

I am using sublime text 2 as the editor for my programs and using this code
{ "cmd": ["g++", "$file", "-o", "$file_base_name"],
"selector": "source.c++", "working_dir": "$file_path",
"variants": [ { "name": "Run", "cmd": ["g++", "$file", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"], "shell": true } ]
}
I am able to run the c++ programs but unable to use test inputs in it.
How do I do that...
P.S. I don't wanna take inputs from any file but give to the console itself.

sublime custom build command, how to?

I have a program, which is using what they called wmake to build the code and it's very convenient. Suppose I have a folder and a C++ file: /path/to/file.C, all I have to do is go to /path/to folder and then type the wmake command and return and all is set.
When I am using sublimetext, I would like to open this file.C file and then ctrl+B to build it, but it doesn't work. Currently I customized a build system like:
{
"cmd": "wmake"
}
the error shows as
[Errno 2] No such file or directory
[cmd: wmake]
[dir: /path/to/file.C]
[path: /home/meee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin]
[Finished]
Anyone knows how to customize a build system in sublimetext2? I read the online mannual but still have no clue. Thanks
My aim
All I want to do is to get the same effect as I type in shell window a simple
wmake /path/to
Edit-1
I tried this, it's not working either, the same error. I dont understand why "no such file"?
{
"cmd": "wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "wmake '${file_path}'"]
}
]
}
Edit-2
I tried using full path of wmake, and the error complains environment variable $WM_OPTIONS not set. So in shell, every time the ~/.bashrc is auto loaded, and to initialize all the environment variables, but this is not so in Sublime!!!!!!!!!!!!! What should I do???
{
"cmd": "/fullpath/to/wmake",
"selector" : "source.C",
"shell": false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/fullpath/to/wmake '${file_path}'"]
}
]
}
Your build command isn't complete. See my customized C build:
{
"cmd" : ["/usr/local/gfortran/bin/gcc", "$file_name", "-o", "${file_base_name}", "-lgsl","-lgslcblas", "-lm" , "-Wall"],
"selector" : "source.c",
"shell":false,
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "/usr/local/gfortran/bin/gcc '${file}' -lgsl -lgslcblas -lm -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}

folder path in sublime text build system

My sublime project looks like this:
{
"folders":
[
{
"folder_exclude_patterns":
[
".bzr",
"build",
"webapps",
"work",
".settings"
],
"path": "/home/charles/project/Editor/trunk"
}
],
"settings":
{
"build_on_save": true,
"filename_filter": "\\.(java)$",
"tab_size": 4,
"translate_tabs_to_spaces": false
},
"build_systems":
[
{
"name": "compile",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
}
When I save a file the console says:
Buildfile: dev.xml does not exist!
Build failed
[Finished in 0.2s with exit code 1]
I know that I need to put something before dev.xml but I don't know what.
I found some possibilities here: http://sublimetext.info/docs/en/reference/build_systems.html#variables
But What I need is the folder path "/home/charles/project/Editor/trunk" in my case...
Any idea how I can achieve this?
You are missing "working_dir" in your "build_systems" setup. The example below will use the directory that holds the sublime project file as the build starting directory.
"build_systems":
[
{
"name": "compile",
"working_dir": "${project_path}",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
More information can be found at: http://www.sublimetext.com/docs/2/projects.html