How to launch an F# console app from VS Code - f#

Given a simple F# console app:
[<EntryPoint>]
let main argv =
printfn "Hello world"
Console.ReadLine() |> ignore
0
What do I need to do to start the console app up in the same manner that ctrl F5 would do in Visual Studio.
I have tried running it form a FAKE build script using the Fake.ProcessHelper:
Target "Run" (fun _ ->
let exe = #"C:\Source\code\fs_console_app\build\fs_console_app.exe"
let errorCode = Shell.AsyncExec(exe, "", buildDir)
()
)
Hitting Ctrl F5 I receive the following build report:
Target Duration
------ --------
Build 00:00:00.3916039
Run 00:00:00.0743197
Total: 00:00:00.5605493
Status: Ok
But no sign of the console application starting up and waiting for input.

I would have preferred to comment but it would be too long, I consider this more of a workaround answer, as I'm not that familiar with Fake. My guess is that your Run Target is actually being executed but is probably being swallowed by AsyncExec or it just shows in the Fake output window (try Exec) but doesn't start a new window.
You can just create a runcmd.bat (assuming you're on windows), and put the following into it, make sure the file is NOT in your build directory as it might get cleaned up:
start C:\Source\code\fs_console_app\build\fs_console_app.exe
You need start to kick off a new cmd window. This could be something else of course, bash or powershell, etc.
Then inside your build.fsx:
Target "Run" (fun _ ->
let exe = "path/to/runcmd.bat"
printfn "%A" "Hello World"
Shell.Exec(exe) |> ignore
)
// Build order
"Clean"
==> "Build"
==> "Run"
==> "Deploy"
Now if I run (via Ctrl+Shift+P) Fake, and pick Run, it compiles, starts a new command line and waits for the ReadLine. It also works via Ctrl+F5.

Related

LSP server on_init per project configuration

I'm noob in Lua and after many hours of searching, it wasn't successful.
I want to load some EFM language server configurations depends on a project setup. So, I found this: https://github.com/neovim/nvim-lspconfig/wiki/Project-local-settings
For example: in A project I have a "black" code formatter, in B project I have "yapf" code formatter.
After that I wrote custom on_init handler:
...
on_init = function(client)
-- We need to register only available linters and formatters, because it improves perfomance↴
local result = vim.fn.systemlist(
[[ poetry run pip list --disable-pip-version-check | grep -w -o '^black \|^yapf \|^flake8 \|^isort \|^mypy ' ]]
for _, package_name in pairs(result) do
local package_config = M[string.gsub(package_name, "%s+", "")]
if package_config then
table.insert(client.config.settings.languages.python, package_config)
end
end
client.notify("workspace/didChangeConfiguration")
return true
end,
...
Well, it works, but i have a problem with a custom command, it's sync and freezes UI on first LSP load. Is it possible to load on_init async or execute cmd async?

how can made lldb server launching a new process without attaching to the existed one?

I'm using ios-deploy to launch ios app automatically, it works fine but only a probem: it won't restart the app if it's already running.
I have studied its source code and learned it's using the lldb command to launch the app. the lldb script is (part):
def run_command(debugger, command, result, internal_dict):
device_app = internal_dict['fruitstrap_device_app']
args = command.split('--',1)
error = lldb.SBError()
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))
args_arr = []
if len(args) > 1:
args_arr = shlex.split(args[1])
args_arr = args_arr + shlex.split('{args}')
launchInfo = lldb.SBLaunchInfo(args_arr)
global listener
launchInfo.SetListener(listener)
#This env variable makes NSLog, CFLog and os_log messages get mirrored to stderr
#https://stackoverflow.com/a/39581193
launchInfo.SetEnvironmentEntries(['OS_ACTIVITY_DT_MODE=enable'], True)
lldb.target.Launch(launchInfo, error)
lockedstr = ': Locked'
if lockedstr in str(error):
print('\\nDevice Locked\\n')
os._exit(254)
else:
print(str(error))
the start command:
(lldb) command source -s 0
'/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b'
Executing commands in
'/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b'.
(lldb) platform select remote-ios --sysroot
'/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols' Platform: remote-ios Connected: no SDK Path:
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols" (lldb) target create
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app" Current executable set to
'/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app' (arm64). (lldb) script
fruitstrap_device_app="/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35/mj.app"
(lldb) script fruitstrap_connect_url="connect://127.0.0.1:62276"
(lldb) target modules search-paths add /usr
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols/usr" /System
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols/System"
"/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35"
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos"
"/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35"
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos"
/Developer "/Users/wellbye/Library/Developer/Xcode/iOS
DeviceSupport/12.0 (16A366)/Symbols/Developer" (lldb) command
script import
"/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.py"
(lldb) command script add -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.connect_command
connect (lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.run_command run
(lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.autoexit_command
autoexit (lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.safequit_command
safequit (lldb) connect (lldb) run
I have searched the lldb's python api reference, but haven't seen anything (args or flags) I could use for my purpose.
so how could we let the lldb server know it should kill the exist process and start a new one?
It depends on whether you are trying to support rerun behavior (i.e. you make a target, launch the process, then use the same target to re-run) or if you just want to kill off some instance of the app that was running - maybe because it was finger-launched on the device or whatever.
In the first case, since you are reusing the SBTarget, you can just check whether your target has a process (call target.process.IsValid()) and if does kill it with target.process.Kill() before launching.
But if lldb is not responsible for launching the extant copy of the app, then it won't know anything about it, and doesn't really have a way to kill it off.

where does the log is created by default in FAKE F#Make?

I am trying to build a csproj file with FAKE, following the "Getting started with FAKE - F# Make" tutorial from the FAKE website. I am trying to understand what this line is doing:
|> Log "AppBuild-Output: "
I understand that it is creating the log of the respective build. But where is this log file being created?
This is the code:
Target "BuildApp" (fun _ ->
!! "src/app/**/*.csproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
When I delete the last line, i.e. if i write:
Target "BuildApp" (fun _ ->
!! "src/app/**/*.csproj"
|> MSBuildRelease buildDir "Build"
)
I am getting an error, type 'unit' doesn't match the type 'string list'.

How do I run a .lua script in Notepad++?

I have a very basic .lua file saved in a folder, with just the code
print("Hello world")
I additionally have the standalone lua interpreter downloaded, but it is beyond me how to successfully run my code. I put all the files of the interpreter in the same folder but when I use F5 to run the program I see no text in the interpreter.
Run Notepad++.
On the menu select: Run -> Run.. (F5).
Insert: C:\path\to\lua.exe "$(FULL_CURRENT_PATH)"
Now you can run your scripts by pressing F5 on your keyboard.
Just do it with NppExec plugin:
SET interpreter = F:\lua\lua53.exe
SET exec = "$(interpreter)" "$(FULL_CURRENT_PATH)"
NPP_SAVE
$(exec)
if $(EXITCODE) != 0 goto exit
NPP_CONSOLE 0
NPP_RUN cmd /C "cmd /C $(exec) && pause"
:exit
KaMehHb's answer is correct, but one thing to add is either delete this line or change it to 1 if you want the console to stay up.
NPP_CONSOLE 0
to
NPP_CONSOLE 1

Erlang how to start an external script in linux

I want to run an external script and get the PID of the process (once it starts) from my erlang program. Later, I will want to send TERM signal to that PID from erlang code. How do I do it?
I tried this
P = os:cmd("myscript &"),
io:format("Pid = ~s ~n",[P]).
It starts the script in background as expected, but I dont get the PID.
Update
I made the below script (loop.pl) for testing:
while(1){
sleep 1;
}
Then tried to spawn the script using open_port. The script runs OK. But, erlang:port_info/2 troughs exception:
2> Port = open_port({spawn, "perl loop.pl"}, []).
#Port<0.504>
3> {os_pid, OsPid} = erlang:port_info(Port, os_pid).
** exception error: bad argument
in function erlang:port_info/2
called as erlang:port_info(#Port<0.504>,os_pid)
I checked the script is running:
$ ps -ef | grep loop.pl
root 10357 10130 0 17:35 ? 00:00:00 perl loop.pl
You can open a port using spawn or spawn_executable, and then use erlang:port_info/2 to get its OS process ID:
1> Port = open_port({spawn, "myscript"}, PortOptions).
#Port<0.530>
2> {os_pid, OsPid} = erlang:port_info(Port, os_pid).
{os_pid,91270}
3> os:cmd("kill " ++ integer_to_list(OsPid)).
[]
Set PortOptions as appropriate for your use case.
As the last line above shows, you can use os:cmd/1 to kill the process if you wish.

Resources