Running paraview python through commandline - paraview

Is there any way to run a python script of paraview using command line.
right now I can open the file in "python shell" in paraview and get results. I am not able to figure out away to run it through commandline. Can you please tell me the syntax of running it.
import os
i=0
SubDir = [" "]*30
# Set the directory you want to start from
rootDir = '/var/www/html/php/emd/job552e23fe74d102/VTK'
for dirName, subdirList, fileList in os.walk(rootDir):
if dirName == rootDir + '/others':
continue
if dirName == rootDir:
continue
SubDir.append(dirName)
i=i+1
print('Found directory: %s' % dirName)
for fname in fileList:
print('\t%s' % fname)
j=1
j= LegacyVTKReader( FileNames=[dirName + '/' + fname] )
This my code

You should call the script with pvpython from the bin.
pvpython /dir/script.py
Make sure to utilize the gui Trace options in the ParaView Python shell to make sure your code is correct before running it.

Related

Is there a good way to open a file from within Neovim in a VSCode project?

Say I have a project in a directory called project-foo. This project has multiple files and subdirectories.
In vim/neovim, my pwd is project-foo and my open buffer is project-foo/src/test/bar.js.
How can I open this file in VSCode in the project context (not individual file by itself)?
Another way to ask: is there a way to get VSCode to open with the project context and specifically focus a particular file?
Expanding on this, let's say I want to open the specific file project-foo/src/test/bar.js. I could type `code project-foo/src/test/bar.js'. But that opens VSCode with only awareness of that specific file unless VSCode already has this project open.
I essentially want the equivalent of:
> cd project-foo
> code .
(in VSCode) ⌘+p src/test/bar.js <enter>
but in command line form.
Given it'll open the file in the context of the project if VSCode is already open to the project, you can accomplish this (and handle when VSCode isn't launched) with the following semi-hack:
> cd project-off
> code . && code -g ./src/test/bar.js
In vim/neovim, you could add a keymap that executes the following
:!code . && code -g %
Explanation:
! will run the proceeding text as a shell command
code . will open the current project
&& code % will then execute vscode again but with with the current buffer path (magic %)
An improvement on this if you want to navigate to a particular line and column
vim.keymap.set.("n", "<leader>ox",
function()
local r, c = unpack(vim.api.nvim_win_get_cursor(0))
vim.cmd('!code . && code -g ' .. vim.fn.expand('%') .. ':' .. r .. ':' .. c)
end,
{ desc = '[O]pen E[x]ternal editor' }
)
vim.api.nvim_win_get_cursor(0) gets you the cursor position
!code . && code -g ' .. vim.fn.expand('%') .. ':' .. r .. ':' .. c is ultimately code . && code -g [file]:[row]:[column]

Why can't MATLAB find a script that is on MATLABPATH

I've just created a script file in MATLAB, but can not run it. The name of my script is getEnvFiles.m. When I first tried to run it, I got the following result:
>> getEnvFiles
'getEnvFiles' is not found in the current folder or on the MATLAB path, but exists in:
\\wsl$\ubuntu\home\me
Change the MATLAB current folder or add its folder to the MATLAB path.
So, I added this directory (which is actually the current directory) to the search path, but still got the same result:
>> addpath('\\wsl$\ubuntu\home\me')
>> getEnvFiles
'getEnvFiles' is not found in the current folder or on the MATLAB path, but exists in:
\\wsl$\ubuntu\home\me
Change the MATLAB current folder or add its folder to the MATLAB path.
When I check the path, it looks like this directory is on the path:
>> path
MATLABPATH
\\wsl$\ubuntu\home\me
I can further verify that this directory is my present directory:
>> pwd
ans =
'\\wsl$\ubuntu\home\me'
and that getEnvFiles.m is in this directory:
>> ls
. .emacs.d HarborData
.. .emacs~ RawHarborData
.bash_history .landscape at
.bash_logout .motd_shown getEnvFiles.m
.bashrc .profile test.m
.bashrc~ .sudo_as_admin_successful
.emacs
Is the issue that I'm using wsl (Windows Subsystem for Linux), or do I have some other misunderstanding?
Type rehash and then try running your script again. Even though you have added the new directory to your path, you need to update the path cache so that it knows about the new scripts it can see.
The problem seems to lie in WSL's ability to add new files to the directory. When I create a new script within MATLAB, and try to run it, I get the problem discussed above. However, running already existing files is not a problem. For now, my only solution is to close MATLAB after creating a new script and reopen it. Then, I can run it. Although, oddly, I can't open it in MATLAB's editor.....
This may or may not help, but ...
Sometimes you have to prepend execution with .\ in order to run scripts in PowerShell or from within the command prompt (in Windows, I'm not sure about other operating systems).
I get this error quite often, especially when not in Admin mode.
Does this work?
% Get path of executing script.
filePath = matlab.desktop.editor.getActiveFilename; % Note that this isn't necessarily the same as the output of 'pwd()'.
% Or: filePath = mfilename('fullpath')
% Make sure all nested directories of filePath are on the path, then tell MATLAB where you're working.
addpath( genpath( filePath ) ); % If this fails, try one folder up the tree:
% addpath( genpath( fullfile( filePath, '.' ) );
cd( filePath );
Alternatively, it looks like you might have written and saved the script, and then typed it into the command window to execute. If it's not a special type of script (Function/Class/GUI/etc.) then you can simply click 'Run' in the Editor tab (or the F5 key) and MATLAB should prompt you with a 'Change Folder' option, to which you should acquiesce.
If you're running this script through the WSL terminal, try my suggested code.

How can I use relative paths with AutoHotkeys

I'm trying to use relative path in AutoHotKeys so the source control can be checked out and the hotkeys will still work.
Using %A_WorkingDir% gives me the location of the script. From there I need to move up one directory and nagivate down to the script I need to run.
I have tried:
^!a::
Path = %A_WorkingDir%
Run %Path%\..\locationOf\script.cmd
^!a::
Path = %A_WorkingDir%\..
Run %Path%\locationOf\script.cmd
^!a::
Path = %A_WorkingDir% \..
Run %Path%\locationOf\script.cmd
^!a::
Path = %A_WorkingDir% "\.." ; Also removed the space between % and " -> %A_WorkingDir%"\.." but didn't work
Run %Path%\locationOf\script.cmd
I don't really want to do any string manipulation on the working dir to force it unless there is no other way?
Thanks for your help
Try
Run %A_WorkingDir%\..\locationOf\script.cmd
Or
Run "%A_WorkingDir%\..\locationOf\script.cmd"
Or
Run %comspec% /k "%A_WorkingDir%\..\locationOf\script.cmd"
As BGM has said :
Keep in mind that the workingdir can also be changed via a windows launcher or shortcut. If you use a launcher like JetToolbar (my favourite) it sets the workingdir to its own application directory by default. It might be a good idea for the script to set the workingdir to the scriptdir or just use scriptdir instead.
Solution :
SetWorkingDir, %A_ScriptDir%

Lua os.execute() does not work

I'm having a problem with the Lua os.execute() command.
I just want to echo a word and write it into a file, like echo 'aword' > C:\folder\tempworkspace\foo to try the os.execute() command. The direcory C:\folder\tempworkspace exists, "foo" is the name of the file I want the command to create and fill with "aword".
Later, when this works, I'd like to call R, using R -q -e "rbinom(1000,1,0.7)" > C:\folder\tempworkspace\foo.
I've already tried all the advice provided in
Lua programming - os.execute() is not working in Windows and Why won't applications in Program Files run using os.execute in lua?
but my problem seems to be a different one, maybe not even in the syntax, but somewhere else?
When I type those command directly in the Command Prompt, they work. I use Windows 7 Professional as an administrator, and Lua 5.1.4 with Eclipse.
Here is what I have tried so far:
os.execute("echo 'hehe' > C:\folder\tempworkspace\foo")
os.execute [["echo 'hehe' > C:\folder\tempworkspace\foo"]]
os.execute [["echo 'hehe' > 'C:\folder\tempworkspace\foo'"]]
os.execute [[echo 'hehe' > C:\folder\tempworkspace\foo]]
os.execute [[echo 'hehe' > C:\\folder\\tempworkspace\\foo]]
os.execute[[cmd.exe /c echo 'hehe' > C:\folder\tempworkspace\foo]]
os.execute("cmd.exe /c echo 'hehe' > C:\\folder\\tempworkspace\\foo")
os.execute("cmd.exe /c echo 'hehe' > 'C:\\folder\\tempworkspace\\foo'")
I'd be very grateful for any suggestions to improve my code. (Note: I'm writing to a file, because I want to use the output later in lua. Another way of doing this, using io.popen() has been suggested somewhere, but it is said to be platform dependent, anyway my Lua crashes when I try to use x = io.popen("R -q -e 'rnorm(10)'")).
Edit, after first answer:
Your sendMsg function somehow also does not work on my computer, and I don't get any error, I really wonder what's the problem. For pcall, am I doing this right? As the line print(err) does not print anything I wonder if I am doing correctly.
function sendMsg(cmd, msg, fpath)
local output = cmd.. " ".. msg.. " > ".. fpath
print(output)
os.execute(output)
end
function sendMsgArgs()
sendMsg("echo", "huhu", "C:\\merret\\tempworkspace\\foo");
end
err = pcall(sendMsgArgs)
if err == true then
print("THIS WORKED")
else
print("THIS DID NOT WORK")
print(err)
end
Edit: This was actually a Eclipse/editor issue. So I wanted to add some tags, such as lua-eclipse, but I can't.
it's been a while, but finally (thanks to a colleague), I figured out that the problem was not the Lua code, but actually executing Lua from Eclipse (I'm using the Lua Eclipse plugin).
Executing a lua file with the code
x = os.execute('R -q -e rnorm(10) > C:/folder/something/foo')
print(x)
from the command prompt or using Crimson Editor (see below), it worked perfectly, and returned status code 0 (instead of -1 when executing from Eclipse).
Thanks a lot to all helpers anyway!
That Thing
PS: For anyone who is interested, I'm using Lua as part of the TerraME environment, http://www.terrame.org/doku.php. There is also a description there how to use Crimson Editor.
this snippet of code works on my Win7 box:
function sendMsg(cmd, msg, fpath)
local output = cmd.. " ".. msg.. " > ".. fpath
print(output)
os.execute(output)
end
sendMsg("echo", "hehe", "C:\\path\\to\\foo");
you need to make sure the file exists before you attempt to write to it. are you running this from the lua interpreter? do you get any error messages back when it fails to do the write?
alternatively - you can just use io.open() and write that way. wrapping this in a function and calling it using pcall() may give you more information if you have some sort of windows issue opening/reading to that location.
local fout = io.open("C:\\path\\to\\foo", "w+")
fout:write("hehe")
fout:close()
an example using pcall:
local result, error = pcall(sendMsg, "echo", "huhu", "C:\\merret\\tempworkspace\\foo")
if result == false then
print(error)
else
print("success!")
end
If the path you're trying to write to contains a space, it must be surrounded by double quotes under Windows; single quotes will throw an error.
As such, the following works fine for me:
os.execute([[ echo test > "C:\\Program Files\\xyz.txt" ]])

Displaying the directory list

Trying the following program in Eclipse.
List<String> command = new ArrayList<String>();
String fs = System.getProperty("file.separator");
command.add("C:\\cygwin" + fs + "bin" + fs + "sh");
command.add("-c");
command.add("dir");
ProcessBuilder builder = new ProcessBuilder(command);
final Process process = builder.start();
but the output is;
..Error..
/usr/bin/sh: dir: command not found
Can somebody tell me what is the problem with this code?
You're invoking C:\cygwin\bin\sh, the Cygwin Bourne shell, from a non-Cygwin program.
That's fine, but the Cygwin process doesn't have the same $PATH it would have if you instead logged into Cygwin. That's why sh can't find the dir command.
Try changing this:
command.add("dir");
to this:
command.add("/bin/dir");
Note that "/bin/dir" is the Cygwin-style path for the dir command, which is what sh recognizes.
An alternative would be to set $PATH in the sh process, for example by invoking it as:
C:\cygwin\bin\sh -c "PATH=/usr/bin dir"
(I'll leave it to you to translate that into a form usable with Processbuilder.)