I am currently using :
Runtime.getRuntime().exec("open -a Terminal" + directory + " " + argument);
My argument happens to also be a directory.
My problem is that it will open argument instead of considering it an argument of directory. The outcome will be the same as running the following:
Runtime.getRuntime().exec("open -a Terminal" + directory)
and
Runtime.getRuntime().exec("open -a Terminal" + argument)
Instead of typing directly in a terminal :
$/Users/xxxxx/RestOfPath /Users/xxxxx/argument
Is there a solution which would look like this without parenthesis?
Runtime.getRuntime().exec("open -a Terminal (" + directory + " " + argument+ ")");
Thank you!
You could try escaping the space
Runtime.getRuntime().exec("open -a Terminal" + directory + "\\ " + argument);
Related
In my Powershell script, I use "rmtshare.exe" to get information about share level permission. The "rmtshare.exe" can run perfectly under CMD environment with following command:
rmtshare.exe \\fs-sw-206\"C&C FQT"
However, when I bring it to powershell environment. I can't figure out how to escape the space and the ampersand. Here is what I have tried so far which it is not working:
$rmtShare = "C:\rmtshare.exe"
$ServerName = "fs-sw-206"
$ShareName = "C&C FQT"
Invoke-Expression ($rmtShare + " " + "\\" + $ServerName + "\" + $ShareName)
The script above will give error message from the CMD, it said "if a sharename or path contains spaces, it should be enclosed in quotes".
If I changed the last line to this:
Invoke-Expression ($rmtShare + " " + "\\" + $ServerName + "\" + "'"+'"'+"'" + $ShareName +"'"+'"'+"'")
The error message was from Powershell itself, it said "The ampersand (&) character is not allowed". NOTE: if there is no ampersand, it works. So, now I am stuck because I need to escape both characters at the same time.
Please offer your solution.
You may need to download the rmtshare.exe to test out yourself. Download site: (https://www.symantec.com/connect/downloads/remove-folder-share-remote-computer)
so, here is the code in Powershell that overcame the problem - escape space and ampersand in same time in powershell script that execute CMD
$s = " "
$q = '"'
$Verbatim = '--%'
$rmtShare = "C:\rmtshare.exe"
$ServerName = "fs-sw-206"
$ShareName = "C&C FQT"
Invoke-Expression ($rmtShare +$s+$Verbatim+$s+"\\"+$ServerName+"\"+$q+$ShareName+$q)
There should be other solutions as well. Please post if you know it.
my build script has the following task
task editProjectArtificat (type:Exec) {
executable "sed"
args "-e '/myInsertionMatchingPattern/r " + projectDir.toString() + "/scripts/install/myTextFileToInsert' < " + projectDir.toString() + "/build/scripts/MyOriginalInputFile > " + projectDir.toString() + "/build/scripts/MyChangedOutputFile"
}
gradle build fails when the above task executes with this error message
sed: 1: " '/myInsertionPattern/r ...": invalid command code
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':MyProject:editProjectArtificat'.
Process 'command 'sed'' finished with non-zero exit value 1
However, when I change the gradle.build script to make the task look like this
task editProjectArtificat (type:Exec) {
executable "sed"
args "-e /myInsertionMatchingPattern/r " + projectDir.toString() + "/scripts/install/myTextFileToInsert < " + projectDir.toString() + "/build/scripts/MyOriginalInputFile > " + projectDir.toString() + "/build/scripts/MyChangedOutputFile"
}
Now that both of the "'" removed in the "arg" line, we no longer get gradle build errors; however, sed does not produce "MyChangedOutputFile" file as expected when gradle build is done.
Typing sed command with both "'" on a shell produces the expected output? sed fails when the "'" are removed on the shell. my understanding sed needs "'" around the matching pattern and commands.
I don't know gradle, but it seems like args needs a list with each argument separated. However, you are using redirection (< and >) and that has to be done by the shell, so you shouldn't be executing sed but bash. You want to have something like bash -c "sed -e '/.../r ...' <... >..." so something like this might work:
task editProjectArtificat (type:Exec) {
executable "bash"
args "-c", "sed -e '/myInsertionMatchingPattern/r " + projectDir.toString() + "/scripts/install/myTextFileToInsert' < " + projectDir.toString() + "/build/scripts/MyOriginalInputFile > " + projectDir.toString() + "/build/scripts/MyChangedOutputFile"
}
i have a problem with path in a tcl file i tried to use
source " /tmp/mob.tcl "
and this path in bash file :
/opt/ns-allinone-2.35/ns-2.35/indep-utils/cmu-scen-gen/setdest/setdest -v 1 -n $n -p 10 -M 64 -t 100 -x 250 -y 250 >> /tmp/mob.tcl
but terminal give me this error :
couldn't read file " /tmp/mob.tcl ": no such file or directory
while executing
"source.orig { /tmp/mob.tcl }"
someone can help me please
Learn to believe the error messages you get ;-).
couldn't read file " /tmp/mob.tcl ": no such file or directory
This is because you have submitted a string with the first letter (and the last) of the path being a " " char, i.e.
source " /tmp/mob.tcl "
try submitting
source "/tmp/mob.tcl"
IHTH
I have a script I am working on that reads off of a text file and will use the information stored in the text file to put each line entered in as an array. This array is a reference to files that are imported to a directory in another script. The problem is i built a function to zip the contents of the directory and change it's ownerships, but when I run the script it was zipping and attempting to change ownerships of the pwd. Here is my code below:
file=~/exporttool/zipFiles.txt
index=0
declare -a studyinstanceuids
while read line ; do
studyinstanceuids[$index]="$line"
index=$((index+1))
echo $line
done < $file
for i in "${studyinstanceuids[#]}"
do
echo "$i" | ./cmd2;
done
echo "Exams are in!";
##Function with argument that will take prompt to change ownerships
echo "What is the name of the owner: "
read $owner
zipForOwner(){
arg1=$1
for i in "${studyinstanceuids[#]}"; do
zip -r ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip .
sudo chown $1:$1 ~/export/"${studyinstanceuids[#]}"/"${studyinstanceuids[#]}".zip
sudo mv ~/export/"${studyinstanceuids[#]}"/"${studyinstanceuids[#]}".zip ~/home/"$1"
done
}
zipForOwner $owner
exit;
Does anyone have any suggestions
EDIT: Heere are my results running in xterm
+ file=/home/support/exporttool/zipFiles.txt
+ index=0
+ declare -a studyinstanceuids
+ read line
+ studyinstanceuids[$index]=1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ index=1
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ read line
+ for i in '"${studyinstanceuids[#]}"'
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ ./cmd2
Please enter StudyInstanceUID:
+ echo 'Exams are in!'
Exams are in!
+ echo 'What is the name of the owner: '
What is the name of the owner:
+ read
sftpuser
+ zipForOwner
+ arg1=
+ for i in '"${studyinstanceuids[#]}"'
+ zip -r /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/20140620_1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip .
adding: .studiesToExportSend.txt.swp^C
zip error: Interrupted (aborting)
+ sudo chown : /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip
[sudo] password for support:
This line is your problem:
zip -r ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip .
You're attempting to create a zip file called ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip (good) with all of the contents in the current directory . (bad).
You need to change the . to be the folder you want zipped.
I am trying to configure vim's 'path' and 'suffixesadd' so when I use gf over FILE_NAME, and pwd is /some/dir/, it opens /some/dir/FILE_NAME/File_Name.xml
In vimrc I put:
set suffixesadd=.xml
set path=.,dir/**
But, instead of opening File_Name.xml it opens the directory FILE_NAME
What should I do to configure vim so it looks for files before directories?
PS: Im using gvim in Windows and have NERD plugin active
I don't think this is possible with gf as standard, but you could always do:
" Mapping to make it easier to use - <C-R><C-W> inserts the Word under
" the cursor
nmap gx :call CustomGFOpen("<C-R><C-W>")<CR>
" The function that does the work
function! CustomGFOpen(cursor_word)
" The directory name (e.g. FILE_NAME) is passed as the parameter
let dirname = a:cursor_word
" This is a regular expression substitution to convert
" FILE_NAME to File_Name
let filename = substitute(a:cursor_word, '\(^\|_\)\#<=\([A-Z]\)\([A-Z]\+\)', '\=submatch(2) . tolower(submatch(3))', 'g')
" The extension
let extension = '.xml'
" Join the whole lot together to get FILE_NAME/File_Name.xml
let relative_path = dirname . '/' . filename . extension
" Open that file
exe 'e' relative_path
endfunction