Xcode 4.6 / 5 with lldb breakpoints not working - xcode

I had a problem with using debugger LLDB,
if in "main.c" , I include another file like "a.c" , and set breakpoint in "a.c"
the breakpoint will never been stopped.
Is anyone else getting this?
ok, here is the example
// main.c
#include "a.c"
int main()
{
test();
}
// a.c
void test()
{
return; // (Using UI to)set break point here, the gdb will stop, and lldb will not
}
======================================================================
To trojanfoe:
I had tried these steps in Xcode 4.6.3 command line utilities,
the result is like yours, but my problem is on GUI,
When I use the mouse to set a break point on "a.c", it will not work.
I had tried to stop on main(), and enter this cmd "br list",
here is the message on console,
(lldb) br list
Current breakpoints:
1: file ='a.c', line = 13, locations = 0 (pending)
2: file ='main.c', line = 15, locations = 1, resolved = 1
2.1: where = test`main + 15 at main.c:15, address = 0x0000000100000f3f, resolved, hit count = 1
(lldb)
if you need the log by using command line utilities, please tell me,
thanks~

See "File and line breakpoints are not getting hit" in http://lldb.llvm.org/troubleshooting.html - that seems to be talking about exactly your build scenario, and I've just had this problem. To solve it I not only had to put this in $HOME/.lldbinit:
settings set target.inline-breakpoint-strategy always
I also had to do a clobber (distclean) build and restart Xcode.

NOTE This is not an answer, however I wanted to document the works for me response fully.
OP: Please follow these steps to see how it differs for you.
$ clang -g -o bptest main.c
$ ls -l
total 32
-rw-r--r-- 1 andy staff 110 Oct 31 10:55 a.c
-rwxr-xr-x 1 andy staff 4664 Oct 31 10:56 bptest
drwxr-xr-x 3 andy staff 102 Oct 31 10:56 bptest.dSYM (NOTE THIS)
-rw-r--r-- 1 andy staff 42 Oct 31 10:55 main.c
$ lldb
(lldb) target create bptest
Current executable set to 'bptest' (x86_64).
(lldb) break set -b test
Breakpoint 1: where = bptest`test + 4 at a.c:4, address = 0x0000000100000f34
(lldb) run
Process 9743 launched: '/Users/andy/tmp/bptest/bptest' (x86_64)
Process 9743 stopped
* thread #1: tid = 0x65287, 0x0000000100000f34 bptest`test + 4 at a.c:4, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
frame #0: 0x0000000100000f34 bptest`test + 4 at a.c:4
1 // a.c
2 void test()
3 {
-> 4 return; // (Using UI to)set break point here, the gdb will stop, and lldb will not
5 }
(lldb) bt
* thread #1: tid = 0x65287, 0x0000000100000f34 bptest`test + 4 at a.c:4, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
frame #0: 0x0000000100000f34 bptest`test + 4 at a.c:4
frame #1: 0x0000000100000f49 bptest`main + 9 at main.c:4
frame #2: 0x00007fff8eb3f7e1 libdyld.dylib`start + 1
(lldb)
Note: I am using the Xcode 5.0.1 command line utilities.

Related

Godot - Game 'executable' won't find resources

there.
When using Godot 3.2.2 stable (all templates updated) to export for OSX (from High Sierra) and Windows (VMWare with Windows 10) , many resources are not find, by the interpreter.
While testing in the IDE, everything runs perfectly.
I already changed files names (avoiding spaces and non alphanumeric and '_' characters), deleted everything from the '.import' folder and re-imported all files, and even changed my code to avoid loading stuff 'on the fly', in order to have all resources properly referred in the resulting code.
The files are in their original folders, their '.import' files are there too and mapping to existing files in the '.import' folder.
I was able, too, to check the '.pck' file and the '.wav', '.ogg' and '.png' files are there.
The game will prompt messages like:
ERROR: _load: No loader found for resource: res://sounds//Starting_Lights.ogg.
At: core/io/resource_loader.cpp:285.
ERROR: _load: No loader found for resource: res://sounds//Testing.wav.
At: core/io/resource_loader.cpp:285.
ERROR: _load: No loader found for resource: res://sprites//Backlash_Pic.png.
At: core/io/resource_loader.cpp:285.
ERROR: _load: No loader found for resource: res://sprites//Backlash_Grand_Prix.png.
At: core/io/resource_loader.cpp:285.
One of the 'not found' resource '.import' files has
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Backlash_Grand_Prix.png-ad663db21f8bfbe75b0464e994ebbe2f.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/Backlash_Grand_Prix.png"
dest_files=[ "res://.import/Backlash_Grand_Prix.png-ad663db21f8bfbe75b0464e994ebbe2f.stex" ]
and all indicated files are there
AnJo888i7:sprites AnJo888$ pwd
/Users/AnJo888/Desktop/Godot/project_mr/sprites
AnJo888i7:sprites AnJo888$ ls -l Back*
-rw-r--r--# 1 AnJo888 staff 55120 9 Jun 21:31 Backlash_Grand_Prix.png
-rw-r--r--# 1 AnJo888 staff 693 7 Jul 18:36 Backlash_Grand_Prix.png.import
-rw-r--r--# 1 AnJo888 staff 255514 29 Jun 16:40 Backlash_Pic.png
-rw-r--r-- 1 AnJo888 staff 672 7 Jul 18:36 Backlash_Pic.png.import
AnJo888i7:sprites AnJo888$ ls -l ../.import/Back*
-rw-r--r-- 1 AnJo888 staff 91 7 Jul 18:35 ../.import/Backlash.obj-1faf80b2c76bbdff34635db74f883c59.md5
-rw-r--r-- 1 AnJo888 staff 879958 7 Jul 18:35 ../.import/Backlash.obj-1faf80b2c76bbdff34635db74f883c59.mesh
-rw-r--r-- 1 AnJo888 staff 91 7 Jul 18:35 ../.import/BacklashFF.obj-1f7907e7c14594be339288bdbcc49d13.md5
-rw-r--r-- 1 AnJo888 staff 1134886 7 Jul 18:35 ../.import/BacklashFF.obj-1f7907e7c14594be339288bdbcc49d13.mesh
-rw-r--r-- 1 AnJo888 staff 91 7 Jul 18:36 ../.import/Backlash_Grand_Prix.png-ad663db21f8bfbe75b0464e994ebbe2f.md5
-rw-r--r-- 1 AnJo888 staff 55358 7 Jul 18:36 ../.import/Backlash_Grand_Prix.png-ad663db21f8bfbe75b0464e994ebbe2f.stex
-rw-r--r-- 1 AnJo888 staff 91 7 Jul 18:36 ../.import/Backlash_Pic.png-802dae49352de96e7456539e639a1c34.md5
-rw-r--r-- 1 AnJo888 staff 268132 7 Jul 18:36 ../.import/Backlash_Pic.png-802dae49352de96e7456539e639a1c34.stex
AnJo888i7:sprites AnJo888$
So... although all seems to be in place, the game will not play music/sounds (some sounds are played and I changed the loading code, for the others, in order to make everything as equal as possible, without success - all sounds are loaded by a couple os singletons) and not show some textures (mainly stuff loaded during the game execution).
These sounds load and play:
extends AudioStreamPlayer
var audioTeamsFiles = ["res://sounds/Team_Braillewalk.ogg",
"res://sounds/Team_Candy_Cane.ogg",
...
"res://sounds/Team_Cash_is_King.ogg",
"res://sounds/Team_Watermelon.ogg"
]
var audioTeamName
var names = Array()
var volSpeech
func _ready() -> void:
volSpeech = get_node("/root/Globals").volSpeech
for i in range(audioTeamsFiles.size()):
audioTeamName = AudioStreamPlayer2D.new()
audioTeamName.stream = load(audioTeamsFiles[i])
audioTeamName.volume_db = volSpeech
names.append(audioTeamName)
add_child(names[i])
func say_team_name(team):
names[team].play()
func shut_team_name(team):
names[team].stop()
func set_volume():
volSpeech = get_node("/root/Globals").volSpeech
for i in range(audioTeamsFiles.size()):
names[i].volume_db = volSpeech
These will not load:
extends AudioStreamPlayer
var audioSoundFiles = ["res://sounds/Live_the_Life.ogg",
"res://sounds//Love_the_Sound.ogg",
"res://sounds//Love_this_Song.ogg",
...
"res://sounds//Vuvuzelas.ogg"
]
var audioSound
var sounds = Array()
var volEffects
var volMusic
var volSpeech
onready var globals
func _ready() -> void:
globals = get_node("/root/Globals")
for i in range(audioSoundFiles.size()):
audioSound = AudioStreamPlayer2D.new()
audioSound.stream = load(audioSoundFiles[i])
sounds.append(audioSound)
add_child(sounds[i])
set_volume()
play_sound(0)
func play_sound(sound):
sounds[sound].play()
func quiet_sound(sound):
sounds[sound].stop()
func set_volume():
volEffects = globals.volEffects
volMusic = globals.volMusic
volSpeech = globals.volSpeech
for i in range(audioSoundFiles.size()):
if i == 0:
sounds[i].volume_db = volMusic
elif i < 6:
sounds[i].volume_db = volSpeech
else:
sounds[i].volume_db = volEffects
I even included all kind of extensions, available in the export feature, and pointed the sprites and sounds folders, to be included (I used the triple slash I saw in some other reference to Godot's exporting 'issues').
[preset.0]
name="Mac OSX"
platform="Mac OSX"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter="res:///sounds/*, res:///sprites/*"
exclude_filter=""
export_path="./AGC.dmg"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""
[preset.0.options]
custom_template/debug=""
custom_template/release=""
application/name="Absolutely Goode Championship"
application/info="Made with Godot Engine"
application/icon="res://AGC_Icon_256.png"
application/identifier="com.AGC.game"
application/signature=""
application/short_version="1.0"
application/version="1.0"
application/copyright=""
display/high_res=false
privacy/camera_usage_description=""
privacy/microphone_usage_description=""
codesign/enable=false
codesign/identity=""
codesign/timestamp=true
codesign/hardened_runtime=true
codesign/entitlements=""
codesign/custom_options=PoolStringArray( )
texture_format/s3tc=true
texture_format/etc=true
texture_format/etc2=true
It would be great if somebody could help me figure out what I'm missing here...
Btw, if I copy the sprites and sounds folders with the '.exe' in Windows, everything works fine and I was willing to use the same fix for the OSX version (regardless the duplicated files), but not even copying those folders to the app package worked.
Thanks in advance for all answers.
So... after the realization that some of my paths were wrong, I revised all of them and, after correcting the 'wrong' ones, the exported game is working OK.
The issue is that Godot's IDE is quite forgiving when it comes to find files and such, even if we make mistakes like using double slashes (in other places than 'res://') when pointing to resources.
Not trying to lessen the programmer's responsibility to get things done right, but it would've been better, IMHO, if the IDE had punched me in the face earlier, saying: "Your F-ing files are not available, in the F-ing folders you F-ing said they were."... or something like that.
Anyway... as the Lego Movie stated... Everything is Awesome...

How to eliminate JIT overhead in a Julia executable (with MWE)

I'm using PackageCompiler hoping to create an executable that eliminates just-in-time compilation overhead.
The documentation explains that I must define a function julia_main to call my program's logic, and write a "snoop file", a script that calls functions I wish to precompile. My julia_main takes a single argument, the location of a file containing the input data to be analysed. So to keep things simple my snoop file simply makes one call to julia_main with a particular input file. So I'd hope to see the generated executable run nice and fast (no compilation overhead) when executed against that same input file.
But alas, that's not what I see. In a fresh Julia instance julia_main takes approx 74 seconds for the first execution and about 4.5 seconds for subsequent executions. The executable file takes approx 50 seconds each time it's called.
My use of the build_executable function looks like this:
julia> using PackageCompiler
julia> build_executable("d:/philip/source/script/julia/jsource/SCRiPTMain.jl",
"testexecutable",
builddir = "d:/temp/builddir4",
snoopfile = "d:/philip/source/script/julia/jsource/snoop.jl",
compile = "all",
verbose = true)
Questions:
Are the above arguments correct to achieve my aim of an executable with no JIT overhead?
Any other advice for me?
Here's what happens in response to that call to build_executable. The lines from Start of snoop file execution! to End of snoop file execution! are emitted by my code.
Julia program file:
"d:\philip\source\script\julia\jsource\SCRiPTMain.jl"
C program file:
"C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c"
Build directory:
"d:\temp\builddir4"
Executing snoopfile: "d:\philip\source\script\julia\jsource\snoop.jl"
Start of snoop file execution!
┌ Warning: The 'control file' contains the key 'InterpolateCovariance' with value 'true' but that is not supported. Pass a value of 'false' or omit the key altogether.
└ # ValidateInputs d:\Philip\Source\script\Julia\JSource\ValidateInputs.jl:685
Time to build model 20.058000087738037
Saving c:/temp/SCRiPT/SCRiPTModel.jls
Results written to c:/temp/SCRiPT/SCRiPTResultsJulia.json
Time to write file: 3620 milliseconds
Time in method runscript: 76899 milliseconds
End of snoop file execution!
[ Info: used 1313 out of 1320 precompile statements
Build static library "testexecutable.a":
atexit_hook_copy = copy(Base.atexit_hooks) # make backup
# clean state so that any package we use can carelessly call atexit
empty!(Base.atexit_hooks)
Base.__init__()
Sys.__init__() #fix https://github.com/JuliaLang/julia/issues/30479
using REPL
Base.REPL_MODULE_REF[] = REPL
Mod = #eval module $(gensym("anon_module")) end
# Include into anonymous module to not polute namespace
Mod.include("d:\\\\temp\\\\builddir4\\\\julia_main.jl")
Base._atexit() # run all exit hooks we registered during precompile
empty!(Base.atexit_hooks) # don't serialize the exit hooks we run + added
# atexit_hook_copy should be empty, but who knows what base will do in the future
append!(Base.atexit_hooks, atexit_hook_copy)
Build shared library "testexecutable.dll":
`'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' --sysroot 'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root' -shared '-DJULIAC_PROGRAM_LIBNAME="testexecutable.dll"' -o testexecutable.dll -Wl,--whole-archive testexecutable.a -Wl,--no-whole-archive -std=gnu99 '-IC:\Users\philip\AppData\Local\Julia-1.2.0\include\julia' -DJULIA_ENABLE_THREADING=1 '-LC:\Users\philip\AppData\Local\Julia-1.2.0\bin' -Wl,--stack,8388608 -ljulia -lopenlibm -m64 -Wl,--export-all-symbols`
Build executable "testexecutable.exe":
`'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\gcc.exe' --sysroot 'C:\Users\Philip\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root' '-DJULIAC_PROGRAM_LIBNAME="testexecutable.dll"' -o testexecutable.exe 'C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c' testexecutable.dll -std=gnu99 '-IC:\Users\philip\AppData\Local\Julia-1.2.0\include\julia' -DJULIA_ENABLE_THREADING=1 '-LC:\Users\philip\AppData\Local\Julia-1.2.0\bin' -Wl,--stack,8388608 -ljulia -lopenlibm -m64`
Copy Julia libraries to build directory:
7z.dll
BugpointPasses.dll
libamd.2.4.6.dll
libamd.2.dll
libamd.dll
libatomic-1.dll
libbtf.1.2.6.dll
libbtf.1.dll
libbtf.dll
libcamd.2.4.6.dll
libcamd.2.dll
libcamd.dll
libccalltest.dll
libccolamd.2.9.6.dll
libccolamd.2.dll
libccolamd.dll
libcholmod.3.0.13.dll
libcholmod.3.dll
libcholmod.dll
libclang.dll
libcolamd.2.9.6.dll
libcolamd.2.dll
libcolamd.dll
libdSFMT.dll
libexpat-1.dll
libgcc_s_seh-1.dll
libgfortran-4.dll
libgit2.dll
libgmp.dll
libjulia.dll
libklu.1.3.8.dll
libklu.1.dll
libklu.dll
libldl.2.2.6.dll
libldl.2.dll
libldl.dll
libllvmcalltest.dll
libmbedcrypto.dll
libmbedtls.dll
libmbedx509.dll
libmpfr.dll
libopenblas64_.dll
libopenlibm.dll
libpcre2-8-0.dll
libpcre2-8.dll
libpcre2-posix-2.dll
libquadmath-0.dll
librbio.2.2.6.dll
librbio.2.dll
librbio.dll
libspqr.2.0.9.dll
libspqr.2.dll
libspqr.dll
libssh2.dll
libssp-0.dll
libstdc++-6.dll
libsuitesparseconfig.5.4.0.dll
libsuitesparseconfig.5.dll
libsuitesparseconfig.dll
libsuitesparse_wrapper.dll
libumfpack.5.7.8.dll
libumfpack.5.dll
libumfpack.dll
libuv-2.dll
libwinpthread-1.dll
LLVM.dll
LLVMHello.dll
zlib1.dll
All done
julia>
EDIT
I was afraid that creating a minimal working example would be hard, but it was straightforward:
TestBuildExecutable.jl contains:
module TestBuildExecutable
Base.#ccallable function julia_main(ARGS::Vector{String}=[""])::Cint
#show sum(myarray())
return 0
end
#Function which takes approx 8 seconds to compile. Returns a 500 x 20 array of 1s
function myarray()
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
# PLEASE EDIT TO INSERT THE MISSING 496 LINES, EACH IDENTICAL TO THE LINE ABOVE!
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
end
end #module
SnoopFile.jl contains:
module SnoopFile
currentpath = dirname(#__FILE__)
push!(LOAD_PATH, currentpath)
unique!(LOAD_PATH)
using TestBuildExecutable
println("Start of snoop file execution!")
TestBuildExecutable.julia_main()
println("End of snoop file execution!")
end # module
In a fresh Julia instance, julia_main takes 8.3 seconds for the first execution and half a millisecond for the second execution:
julia> #time TestBuildExecutable.julia_main()
sum(myarray()) = 10000
8.355108 seconds (425.36 k allocations: 25.831 MiB, 0.06% gc time)
0
julia> #time TestBuildExecutable.julia_main()
sum(myarray()) = 10000
0.000537 seconds (25 allocations: 82.906 KiB)
0
So next I call build_executable:
julia> using PackageCompiler
julia> build_executable("d:/philip/source/script/julia/jsource/TestBuildExecutable.jl",
"testexecutable",
builddir = "d:/temp/builddir15",
snoopfile = "d:/philip/source/script/julia/jsource/SnoopFile.jl",
verbose = false)
Julia program file:
"d:\philip\source\script\julia\jsource\TestBuildExecutable.jl"
C program file:
"C:\Users\Philip\.julia\packages\PackageCompiler\CJQcs\examples\program.c"
Build directory:
"d:\temp\builddir15"
Start of snoop file execution!
sum(myarray()) = 10000
End of snoop file execution!
[ Info: used 79 out of 79 precompile statements
All done
Finally, in a Windows Command Prompt:
D:\temp\builddir15>testexecutable
sum(myarray()) = 1000
D:\temp\builddir15>
which took (by my stopwatch) 8 seconds to run, and it takes 8 seconds to run every time it's executed, not just the first time. This is consistent with the executable doing a JIT compile every time it's run, but the snoop file is designed to avoid that!
Version information:
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-6700 CPU # 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 8
JULIA_EDITOR = "C:\Users\Philip\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Looks like you are using Windows.
At some point PackageCompiler.jl will be mature for Windows at which you can try it.
The solution was indeed to wait for progress on PackageCompilerX, as suggested by #xiaodai.
On 10 Feb 2020 what was formerly PackageCompilerX became a new (version 1.0 of) PackageCompiler, with a significantly changed API, and more thorough documentation.
In particular, the MWE above (mutated for the new API to PackageCompiler) now works correctly without any JIT overhead.

Fork() process behaviour

Say I have a piece of a code
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
pid_t p ;
p = fork (); // p is a new process
// three cases -1, 0 , >0
// -1 will report the error
// 0 will tell us that the process is created
int i =0 ;
switch(p)
{
case -1 : printf("Error; \n");
break;
case 0: printf("I am child and my pid is %d",getpid());
printf("\nMy parent pid is : %d\n",getppid());
break;
default:printf("You are inside parent whose pid is %d\n",getpid());
for (int i =20 ; i <= 29; i++)
{
printf("%d\n",i);
}
break;
}
}
This code is giving different outputs in different operating systems. I have Ubuntu 14.04 on my system and OS in our college labs is Red Hat and when we are executing the same program on different machine the output is different.
Output is Like (on my System):
You are inside parent whose pid is 5283
20
21
22
23
24
25
26
27
28
29
I am child and my pid is 5284
My parent pid is : 5283
and the system which is inside the labs is giving the output like
I am child and my pid is 5284
My parent pid is : 5283
You are inside parent whose pid is 5283
20
21
22
23
24
25
26
27
28
29
If we check the program carefully, in my system's output the parent completes the task first and then gives the control to the child process, and on the other system the parent process first creates the child, child first does its task and then resumes back to parent. So what's the difference? Does it depend on the System Architecture or any other parameter like OS. Please let us know
It only depends on the system's scheduler. If you launch your program several times on the same machine, the results may differ.
As soon as two processes are concurrently launched, you can't assume an execution order between their instructions.

In Rust, how can I capture process output with colors?

I would like to capture output from another process (for example git status), process it, and print with all styles (bold, italics, underscore) and colors. It's very important for me to further process that String, I don't want only to print it.
In the Unix world, I think this would involve escape codes, I'm not sure about Windows world but it's important for me too.
I know how to do it without colors:
fn exec_git() -> String {
let output = Command::new("git")
.arg("status")
.output()
.expect("failed to execute process");
String::from_utf8_lossy(&output.stdout).into_owned()
}
Maybe I should use spawn instead?
Your code already works:
use std::process::Command;
fn main() {
let output = Command::new("ls")
.args(&["-l", "--color"])
.env("LS_COLORS", "rs=0:di=38;5;27:mh=44;38;5;15")
.output()
.expect("Failed to execute");
let sout = String::from_utf8(output.stdout).expect("Not UTF-8");
let serr = String::from_utf8(output.stderr).expect("Not UTF-8");
println!("{}", sout);
println!("{}", serr);
}
Prints the output:
total 68
-rw-r--r-- 4 root root 56158 Dec 23 00:00 [0m[44;38;5;15mCargo.lock[0m
-rw-rw-r-- 4 root root 2093 Dec 9 02:54 [44;38;5;15mCargo.toml[0m
drwxr-xr-x 1 root root 4096 Dec 30 15:24 [38;5;27msrc[0m
drwxr-xr-x 1 root root 4096 Dec 23 00:19 [38;5;27mtarget[0m
Note that there's a bunch of junk scattered inside the output ([44;, [0m, etc.). Those are ANSI escape codes, and the terminal emulator interprets those to change the color of the following text.
If you print the string with debugging, you will see:
\u{1b}[0m\u{1b}[44;38;5;15mCargo.lock\u{1b}[0m
Each escape code starts with an ESC (\u{1b}) followed by the actual command. You will have to parse those in order to ignore them for whatever processing you are doing.
Windows does not use escape codes (although maybe it can in Windows 10?), and instead a program directly modifies the console it is connected to. There is nothing in the output to indicate the color.
You can force git to output colors by using git -c color.status=always status
use std::process::Command;
fn main() {
let output = Command::new("git")
.arg("-c")
.arg("color.status=always")
.arg("status")
.output()
.expect("failed to execute process");
let output = String::from_utf8_lossy(&output.stdout).into_owned();
println!("{}", output);
}
This works for git status only. For a more general solution, you either have to check the programs documentation and hope there is a way to force colored output or check how the program determines if it should output colors or not (such as checking for the COLORTERM environment variable).

Renjin could not find function 'engine.eval

I am running Java on Linux (CentOS), via the command line.
When I put the R command is a separate file, described in Section 1.4 of these docs,
I get the error:
Exception in thread "main" org.renjin.eval.EvalException: could not
find function 'engine.eval'
at org.renjin.eval.Context.evaluateFunction(Context.java:269)
at org.renjin.eval.Context.evaluateCall(Context.java:260)
at org.renjin.eval.Context.evaluate(Context.java:193)
at org.renjin.eval.Context.evaluateExpressionVector(Context.java:252)
at org.renjin.eval.Context.evaluate(Context.java:191)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:131)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:127)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:107)
at pkg3.Temp3.main(Temp3.java:31)
I have the CLASSPATH set correctly, because:
cd ~/rjtest
javac pkg3/Temp3.java
cd ~/rjtest
java pkg3.Temp3
produces:
x y
1 1 1.121
2 2 0.525
3 3 1.811
4 4 1.914
5 5 5.389
6 6 8.501
7 7 6.477
8 8 7.805
9 9 8.625
10 10 10.033
Call:
lm(formula = y ~ x, data = df)
Coefficients:
(Intercept) x
-0.902 1.113
Modifing the code to move the 3 engine.eval statements into script.R:
// engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
// engine.eval("print(df)");
// engine.eval("print(lm(y ~ x, df))");
engine.eval(new java.io.FileReader("/pathto/rjtest/pkg3/script.R"));
javac compiles with no error, but java gives the error.
The code engine.eval() is a Java statement. The Exception you're getting is Renjin telling you that there is no R function called engine.eval. Your script.R should contain:
df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))
print(df)
print(lm(y ~ x, df))"
Not:
engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))")
engine.eval("print(df)");
engine.eval("print(lm(y ~ x, df))")
Which is, coincidentally, valid R syntax, but not what you want.

Resources