Displaying the directory list - command

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.)

Related

Running paraview python through commandline

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.

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%

How to run a command without opening new shell using the AutoIt command line

I am currently writing a command line application in AutoIt and am having trouble with making it print back to the same command line I opened it in. My goal is to have the entire program work within a single shell. Here is what I tried initially:
;myprogram.au3
$MyCommand = 'dir'
Run(#ComSpec & " /c " & $MyCommand, #SystemDir, #SW_Show)
Run(#ComSpec & " /c #echo off && echo Command completed successfully. && #echo on", #SystemDir, #SW_Show)
Then I compiled it and ran it via the command line (each code box represents a new shell):
C:\Users\Matthew>myprogram.au3
C:\Users\Matthew>
Opens new shell
↓
Volume in drive C has no label.
Volume Serial Number is 0287-990C
Directory of C:\Users\Matthew
<Finishes normal dir command output>
Once finished, listing files in my directory that exits and
Opens new shell
↓
The command completed successfully.
And that window closes immediately.
The output I am looking for is the same thing, but in one window, like this:
C:\Users\Matthew>myprogram
*Output of dir command*
The command completed successfully
C:\Users\Matthew>
You compile your project as a console application for this to work. You can do that by checking the somewhat cryptically named "Create CUI instead of GUI EXE" checkbox when compiling. Then call myprogram.exe from the shell instead of .au3.
#include <Constants.au3>
;myprogram.au3
$MyCommand = 'dir'
Local $foo = Run(#ComSpec & " /c " & $MyCommand & " \& echo Command completed successfully.", #SystemDir, #SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $output
While 1
$output = StdoutRead($foo)
If #error Then ExitLoop
ConsoleWrite($output)
Wend
Since this question is unanswered:
$MyCommand = 'ping www.google.com && ping www.stackoverflow.com'
Run(#ComSpec & " /c " & $MyCommand, #SystemDir, #SW_Show)
Like this both commands are executed in the same CMD-Box.

Is it possible to execute a command relative to a Terminal shell script?

I have a Terminal shell script file start.command that I launch from finder with:
ls -l
The file is in ~/foo but list ~, can I get the path of it's containing dir. I'd like to launch an application that is in the same folder as the file when the user runs the .command but it seems like I would need the absolute path to the file for that to work.
Assuming bash, you need to cd to the script's enclosing directory before running ls.
You can one-line it with this:
cd "$(dirname "$0")"
$0 is the script's relative path, i.e. whatever you used on the command line to invoke it. dirname strips the filename from the path.
$() is a value expansion to feed to cd, and the quotes are all necessary to handle things like spaces in paths.

mkdir call getting failed in Perl

I am trying to create a directory using Perl. But this call fails.
However when I try to create the same directory structure in shell prompt, it works fine.
Could someone please let me know why I am not able to create the directory in the directory structure?
Example:
$absolutepath = "/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata";
print $absolutepath."\n";
mkdir "$absolutepath" or die $!;
In this example, localdatafs1, Domino, mail\abhy.nsf, and Sent are directories that already exist. I want to create a directory called metadata in the directory structure /localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata using Perl. This mkdir call fails.
If I execute the command
mkdir /localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
in shell prompt, the directory gets created successfully.
Why I am unable to create the directory in Perl using the above path?
Your shell understands a different language than Perl. In your shell, the code
/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
produces the string
/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
In Perl, the code
"/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata"
produces the string
/localdatafs1/Domino/mail?bhy.nsf/Sent/Metadata
where the ? represents a non-printable control character. The Perl code
"/localdatafs1/Domino/mail\\abhy.nsf/Sent/Metadata"
produces the desired string. Note the escaped "\".
$path = "/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata"
^--- escape character, turning the path into
$path = "/localdatafs1/Domino/mail".chr(1)."bhy.nsf/Sent/Metadata"