Q/KDB: How do you call system commands in a lambda/function - kdb

How do you call system commands in a lambda/function?
E.g. I would like to load a q script through .z.ts
Trying .z.ts:{\l myScript.q} does not work. Thanks in advance!

You can use the loading system function in the format
system "l [x]"
For example:
.z.ts:{system "l myscript.q"}
You can find some information about using system commands, like so, here:
https://kx.com/blog/kdb-q-insights-scripting-with-q/

Related

How to Load PowerShell Functions On-Demand?

In my personal PowerShell profile that loads whenever I start PowerShell, I want to include a set of functions by calling a function.
So I want to do something like this:
function loadMyFunctions{
. \MyFunctions.ps1
}
Now, in MyFunctions.ps1 I have a function:
function bobtest{
write-host "My name is Bob Newhart."
}
I am able to load the script MyFunctions.ps1, but after that is loaded I am not able to call bobtest in the console - I get the error message The term bobtest is not recognized...
However, if I just load the script outside the function then that script is loaded and I can call bobtest normally - but that means that I can't just not load MyFunctions when the profile is loaded - I have to load MyFunctions and cannot choose.
You see, I want to load the other functions on demand and not have them available until I choose.
Is there another way to do this or can it even be done?
Have a look at this page, How to Create PowerShell Modules and Manifests.
This will enable you to create a module which will have all your custom functions! Then inside of your loadMyFunctions cmdlet add Import-Module NewModuleName.
This will enable you to use your cmdlets.
Hope this Helps,
Lachlan
Best way is to use modules. But still if you want to get in some different ways , then you can try with your approach.
See the below screenshots which I have performed.
I have a function addition which simply does addition and I saved it as funct1.ps1
Now I am calling the same function from another function of the other script just using dot source without using as module and it results me properly.
Funct1.ps1
Triggered the function from another function in another script .
Hope it helps...!!!

How to run a powershell script from neko haxe?

I need to run a powershell script from haxe code and return data. I will use this data in my code.
How I can do this?
You can run a sys.io.Process from Neko.
Check out the api docs
http://api.haxe.org/sys/io/Process.html
To see an example of how to use it, check this
http://code.haxe.org/category/macros/add-git-commit-hash-in-build.html
In your case it would look like this
var process = new sys.io.Process('powershell', ['any parameters']);
Note: I'm not sure if you really need powershell since you can execute stuff commandline with this.
I hope this helps!

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

Ida pro gragh output batch mode

Can anyone let me know how we are going to output all the subroutine's graphs in batch mode suing IDC. i.e. I have 447 subroutine's and wanna be output them all and I would like to make sure I first retrieve all the routines address automatically, cuz by knowing the address I can simply use GenFuncCall.
P.S: Is this the only cfg that I can get from Ida Pro given a binary dis-assembled file?
I needed a CFG of my whole program,the base example I started from was:
https://code.google.com/p/idapython/source/browse/trunk/examples/ex_gdl_qflow_chart.py
It uses the flow chart class:
https://www.hex-rays.com/products/ida/support/idapython_docs/idaapi.FlowChart-class.html
also worth noting to trigger in batch mode, you'll want something like this
idal64 -A -S{yourscriptname}.py {yourbinary}
Tips:
Prototype the script in the IDAPro gui first
Opening of the graph processor can cause timing issues, its hacky, but something like delaying execution of the script seemed to help, e.g.
idaapi.autoWait()
Timer(2, idacfg).start()
where idacfg is your python function from the example
print to stdout doesn't seem to work in batch mode, so you'll want to set stdout to a file for your debugging.
Closing the GUI in batch mode is still an issue for me.
Hope that helps.
If you just want the address of all known functions in the IDB, you could use something like this using IDAPython (just an example):
def main():
for count, func_ea in enumerate(Functions()):
if func_ea == BADADDR:
break
func_name = GetFunctionName(funcea)
func_start = func_ea
print("[{:4}] name: {}; start address: {:#x}".format(count, func_name, func_start))
if __name__ == "__main__":
main()

Use the tree-view in Atom editor init script

I'm trying to write a init script for the Atom editor to add a custom command to be able to reveal the currently opened editor file in the tree-view with one key combination, instead of two.
Here is an example code (which makes something different) to make clear how it generally has to look like.
atom.commands.add 'atom-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveEditor()
editor.selectLine()
editor.cutSelectedText()
The two commands I need should not be sent to the editor, but to the tree-view. Here are the two commands:
tree-view:toggle-focus
tree-view:reveal-active-file
I assume I have to do something similar as above, like getActiveTreeView or something like that. I tried to google it but it doesn't seem to be obvious. Does someone know how to do this?
It could look something like this:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
tree-view.toggle-focus()
tree-view.reveal-active-file()
You can use the atom.commands.dispatch() method to send a command when getting a hold of the object to send the commands to is hard. In your case, you can use:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')
Sadly, Lee's answer is not correct anymore. Within changes in the API the changed the naming of atom.workspaceView to atom.workspace.
So, if anyone gets here (sure questions and answer is a "bit" old), here's the current working script.
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspace.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspace.element, 'tree-view:reveal-active-file')
#Source
https://discuss.atom.io/t/workspaceview-events/14595/4