I am using sejda-console.bat and I am running into difficulties with parameters when there is a space involved.
I am trying to use the simplesplit feature and I am calling the console as follows:
call sejda-console.bat simplesplit -f %1 -o %~dp1 -s all
If the path to my file is:
Z:\Test\test.pdf
The script works perfectly. However if the path to my file is:
Z:\Test Folder\test.pdf
It fails with the following error:
call sejda-console.bat simplesplit -f "Z:\Test Folder\test.pdf" -o Z:\Test Folder\ -s all
18:16:29.746 Configuring Sejda 1.0.0.M2
18:16:29.777 Loading Sejda configuration form default sejda.xml
18:16:30.027 Starting execution with arguments: 'simplesplit -f Z:\Test Folder\test.pdf -o Z:\Test Folder\ -s all'
18:16:30.027 Java version: '1.7.0_25'
18:16:30.199 Option only takes one value: --output -o value : output directory (required)
I wonder is there anyone who is familiar with the sejda-console or just passing parameters with spaces that could point me in the right direction. I have searched widely and tried all possible combinations of parameters etc.
Thanks
I think you should use quotes for the -o option as well:
call sejda-console.bat simplesplit -f "Z:\Test Folder\test.pdf" -o "Z:\Test Folder\" -s all
I'd suggest to convert the long directory path names to short path names
For example: use C:\TESTFO~1\ as opposed to C:\test folder with spaces
This seems to solve the issue,
Below a working example calling the sejda-console from an AutoIt script
#include <Constants.au3>
Local $iPID, $sOutput = ""
$sFilePath = "C:\test folder with spaces\"
$sFileShort= FileGetShortName($sFilePath)
$iPID = Run(#ComSpec & " /C """ & #ScriptDir & "\sejda-console-2.10.4\bin\sejda-console.bat"" merge -l " & $sFileShort & "files.csv -o " & $sFileShort & "output.pdf --overwrite", "", #SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sOutput = StdoutRead($iPID)
ConsoleWrite($sOutput)
sejdaspacesautoit
Having just hit and solved this exact problem, this is a sample of what I am passing to sedja.
simplesplit -j overwrite -s all -f "C:/Users/user/Desktop/PDF_splitting/pages.pdf" -o "C:/Users/user/Desktop/PDF_splitting/spaced path/" -p [BASENAME]_[CURRENTPAGE]
So, even though my system is Windows 10 I can use forward slash "/" as a path separator. Wrap the whole path in double quotes and it works.
I think the reason a 'normal' path string doesn't work is that the backslash "\" is an escape character in Java.
Related
I try to make a simple shell script to make a jar file. The jar command combined with -C does not work with wildcards. Therefor I use a wildcard to find the files I want. Write them to a file, and loop over them.
It looks something like this:
the_classes=''
cd "$bin_folder"
tmp_dir=$(mktemp -d -t java_sucks)
find "imui/core/" -type f -name "IMUI_Widget_Agent*.class" >"$tmp_dir/classes.txt"
while IFS="" read -r p || [ -n "$p" ]
do
the_classes="${the_classes} -C '$bin_folder' '$p'"
done < "$tmp_dir/classes.txt"
Using the above I complete the command:
cmd='jar cfm build/IMUI_Widget_Agent.jar'
cmd="${cmd} \"$bin_folder/imui/core/IMUI_Widget_Agent_MANIFEST.MF\" $the_classes"
printf "\n\n\ncmd\n\n\n"
echo $cmd
Now if I copy and paste this command to execute it works!
But I want to avoid the manual labour of doing the copy and paste by hand every time.
Now I have:
eval "$("$cmd")"
But I get an error File name too long. No matter what I try, every fix I do creates a new problem. I have been working 6 hours now to make this script.
What would be a good step forward?
Since you cd "$bin_folder" you don't actually need -C "$bin_folder":
#!/bin/bash
shopt -s globstar
cd "$bin_folder"
jar cfm build/IMUI_Widget_Agent.jar \
imui/core/IMUI_Widget_Agent_MANIFEST.MF \
imui/core/**/IMUI_Widget_Agent*.class
However, if you still want to add them as part of a larger script, you can easily and robustly build your command in an array:
#!/bin/bash
shopt -s globstar
cmd=(jar cfm build/IMUI_Widget_Agent.jar imui/core/IMUI_Widget_Agent_MANIFEST.MF)
cd "$bin_folder"
for file in imui/core/**/IMUI_Widget_Agent*.class
do
cmd+=(-C "$bin_folder" "$file")
done
echo "About to execute: "
printf "%q " "${cmd[#]}"
echo
"${cmd[#]}"
Alternatively, you can simply do eval "$cmd" with your code, which is equivalent to echo and copy-pasting. However, be aware that this is fragile and error prone because it requires careful escaping of the filenames which you're not currently doing.
I've been trying to make opencv for linux, I used the cmake parameters:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_OPENCL=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D JAVA_INCLUDE_PATH=$JAVA_HOME/include -D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libawt.so -D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so -D CMAKE_INSTALL_PREFIX=/usr/local
and it generated the files fine.
It was then into around the 81% when it was trting to generate the opencv-jar it opped up with
/home/pi/Desktop/opencv-3.1.0/modules/java/generator/src/cpp/common.h:8:17 fatal error jni.h No such file or directory
So I'm not sure what to be doing now with it. openjdk is installed properly too
Edit: I tried using the -I flag, by doing the command
make -I/usr/lib/jvm/java-8-openjdk-armhf/includes
to no avail
the -I flag on make(1) command only affects the files included in the makefile by the .include directive, not the directories searched for by the compiler. For that purpose, just pass the -I flag to each compilation. One way to do this is
$ make CFLAGS="-I/usr/lib/jvm/java-8-openjdk-armhf/includes"
you can also pass the CFLAGS from the environment, as in
$ export CFLAGS=\""-I/usr/lib/..."\" # escaped double quotes make them to be included in the string.
$ make
Please check: https://stackoverflow.com/a/67154438/1290868
FindJNI
find_package(JNI)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
I have a shell script that executes a Java program with parameters returned from a different Java program.
java -cp $wekaPath $(java GetFilter $WandFDir) -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff
When echoed, it produces the following string:
java -cp /home/robobenny/Documents/WEKA/weka-3-7-4/weka.jar weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval" -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20" -c first -i /home/robobenny/Documents/WEKA/Pipeline/temp/training1_Test.arff -o /home/robobenny/Documents/WEKA/Pipeline/temp/training_1_Test.arff
Which is great, because if I copy the string to the command line, it runs the Java program without incident. The problem arises when I don't echo it and try to execute it from the shell script, and I get the following from the terminal:
<!-- language: lang-none -->
Can't find class called: "weka.attributeSelection.InfoGainAttributeEval"
Filter options:
-S <"Name of search class [search options]">
Sets search method for subset evaluators.
eg. -S "weka.attributeSelection.BestFirst -S 8"
-E <"Name of attribute/subset evaluation class [evaluator options]">
Sets attribute/subset evaluator.
eg. -E "weka.attributeSelection.CfsSubsetEval -L"
Options specific to evaluator weka.attributeSelection.CfsSubsetEval:
-M
Treat missing values as a separate value.
-L
Don't include locally predictive attributes.
Options specific to search weka.attributeSelection.BestFirst:
-P <start set>
Specify a starting set of attributes.
Eg. 1,3,5-7.
-D <0 = backward | 1 = forward | 2 = bi-directional>
Direction of search. (default = 1).
-N <num>
Number of non-improving nodes to
consider before terminating search.
-S <num>
Size of lookup cache for evaluated subsets.
Expressed as a multiple of the number of
attributes in the data set. (default = 1)
General options:
-h
Get help on available options.
(use -b -h for help on batch mode.)
-i <file>
The name of the file containing input instances.
If not supplied then instances will be read from stdin.
-o <file>
The name of the file output instances will be written to.
If not supplied then instances will be written to stdout.
-c <class index>
The number of the attribute to use as the class.
"first" and "last" are also valid entries.
If not supplied then no class is assigned.
When I hard code the output of $(java GetFilter $WandFDir) in the shell script:
java -cp $wekaPath weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval" -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20" -c first -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff
It also runs without incident. Interestingly though, when echoed, the double quotes disappear.
java -cp /home/robobenny/Documents/WEKA/weka-3-7-4/weka.jar weka.filters.supervised.attribute.AttributeSelection -E weka.attributeSelection.InfoGainAttributeEval -S weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20 -c first -i /home/robobenny/Documents/WEKA/Pipeline/temp/training2_Test.arff -o /home/robobenny/Documents/WEKA/Pipeline/temp/training_2_Test.arff
When I leave the double quotes out of the output of $(java GetFilter $WandFDir) I get the following error:
<!-- language: lang-none -->
Illegal options: -T -1.7976931348623157E308 -N 20
Filter options:
-S <"Name of search class [search options]">
Sets search method for subset evaluators.
eg. -S "weka.attributeSelection.BestFirst -S 8"
-E <"Name of attribute/subset evaluation class [evaluator options]">
Sets attribute/subset evaluator.
eg. -E "weka.attributeSelection.CfsSubsetEval -L"
Options specific to evaluator weka.attributeSelection.InfoGainAttributeEval:
-M
treat missing values as a seperate value.
-B
just binarize numeric attributes instead
of properly discretizing them.
Options specific to search weka.attributeSelection.Ranker:
-P <start set>
Specify a starting set of attributes.
Eg. 1,3,5-7.
Any starting attributes specified are
ignored during the ranking.
-T <threshold>
Specify a theshold by which attributes
may be discarded from the ranking.
-N <num to select>
Specify number of attributes to select
General options:
-h
Get help on available options.
(use -b -h for help on batch mode.)
-i <file>
The name of the file containing input instances.
If not supplied then instances will be read from stdin.
-o <file>
The name of the file output instances will be written to.
If not supplied then instances will be written to stdout.
-c <class index>
The number of the attribute to use as the class.
"first" and "last" are also valid entries.
If not supplied then no class is assigned.
I've looked around, and can't seem to find anything that solves my problem.
It's really a catch at the straw, but did you try something like
var="$(java GetFilter $WandFDir)"
java -cp $wekaPath $var -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff
I have a java program that I am trying to generate 3 outputs for, and then rename them depending on what the input file was originally called.
The problem is that only the input file is being moved. I think this might be an issue regarding relative file commands.
Here is my script. (Also, I'm open to suggestions on making this script better looking. I'm a bash newbie.)
#!/bin/bash
########################################################
#This script compiles Main, then attempts to run each #
#test case. After running a test case, it renames the #
#testcase and moves it to a new directory. #
########################################################
#echo `pwd` <---- This was used for testing. pwd is correct
#Gets contents of "tests" directory, stores them into the array
#without the file extension.
list=(`ls tests| sed 's/\.txt$//g'`)
#Compiles Main.java
cd ./src
javac Main.java
cd '../'
mv -f src/*.class bin #*/ (formatting fix)
#Runs Main for each test case, then renames and moves the test cases.
for filename in ${list[#]}
do
echo 1 > input.txt
echo tests/$filename.txt >> input.txt
cd ./bin # Why do I need to cd to make this work?
java bin/Main < input.txt
cd ../
mv -f input.txt "scriptout/'$filename'_input.txt"
mv -f "tests/output.txt" "scriptout/'$filename'_output.txt"
mv -f "tests/listing.txt" "scriptout/'$filename'_listing.txt"
mv -f "src/intermediate.txt" "scriptout/'$filename'_intermediate.txt"
done
You have single quotes around your variable names. Since they're inside double quotes, the variables will be expanded but the single quotes will be included in the filenames. Try this:
mv -f input.txt "scriptout/${filename}_input.txt"
The braces will protect the variable name from being combined with following characters.
You can do this:
list=(tests/*)
list=("${list[#]##*/}") # strip dirname
list=("${list[#]%.*}") # strip extension
These will prevent errors if there are spaces in any of the filenames.
Use indenting to make your script more readable:
for ...
do
command
done
In general, you should avoid using relative directories and use a variable as a base for an absolute directory:
basedir=/path/to/base
do_something $basedir/test/filename
mv $basedir/subdir1/file1 $basedir/subdir2
This can also make it so you don't have to use cd as much.
Are you getting any error messages? Try using set -x to turn on tracing and set +x to turn it off. Place those before and after particular sections of code so you can see what's happening in that area.
I am trying to call a java program in php to use it with web interface.
Java program is dependent on an external lib: commons-cli-1.2.jar
So basically I need to export it before calling the java program; but if I export it first as:
shell_exec('export CLASSPATH=$CLASSPATH:~/lib/commons-cli-1.2.jar');
then call the java program as:
shell_exec('java ComputePagerank -i $para_i -d $para_d -e $para_e -o $para_o');
I think it creates different shells for each call; then the export does not have any effect on java program. Or am I wrong?
Otherwise, it should output a file in the server. But simply it does not. So, what is wrong? Any idea?
edit: However can it be because some parameters such as para_i stands for an input file name, so that i have to specify full path for that? Because I just assume if the input file is in the same working directory, there won't be any problem, will it?
edit-2: it outputs properly when i use command line;)
you're right, each shell_exec creates a separate shell.
env CLASSPATH=whatever java -switches
I would use
shell_exec('java -cp $CLASSPATH:/home/yourname/dir/lib/commons-cli-1.2.jar ComputePagerank -i $para_i -d $para_d -e $para_e -o $para_o > message');
and (this is important) replace the tilde(~) with the actual path to your directory (/home/yourname say). The ~ is expanded by the shell and is dependent on which shell you''re using.
Try Creating a simple shell script with the commands that you want to execute. You may pass arguments to a shell script so that is not a problem either.
for example
echo "Running Script..."
java -cp $CLASSPATH:~/lib/commons-cli-1.2.jar ComputePagerank -i $1 -d $2 -e $3 -o $4 > message
etc.
Then try calling it from the command line first with some parameters. Did it output? Then try calling it from the php script. Did it output? If it did not then you may need to check permissions. I had a simiolar experience some time ago with a Java program that simply did not have permission to write a file.
You should be able to call it like this.
shell_exec('java -cp $CLASSPATH:~/lib/commons-cli-1.2.jar ComputePagerank -i $para_i -d $para_d -e $para_e -o $para_o > message');
Another option is to issue the 2 commands seperately, but to the same shell, like this:
shell_exec('export CLASSPATH=$CLASSPATH:~/lib/commons-cli-1.2.jar; java ComputePagerank -i $para_i -d $para_d -e $para_e -o $para_o > message');
edit:
some shells don't let you call export while you're setting up the variable. so this may be safer than the second option above:
shell_exec('CLASSPATH=$CLASSPATH:~/lib/commons-cli-1.2.jar; export CLASSPATH; java ComputePagerank -i $para_i -d $para_d -e $para_e -o $para_o > message');
another edit:
If none of the above work then you're going to have to do some more trouble shooting. Does your java program work from the command prompt?
java -cp $CLASSPATH:/home/user/lib/commons-cli-1.2.jar ComputePagerank -i param1 -d param2 -e param3 -o param4 > message