Skip to content

Commit 624aef9

Browse files
committed
PDFBOX-5913: don't spawn a cmd / command subprocess to get windir, as suggested by Jakob Heher
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922318 13f79535-47bb-0310-9956-ffa450edef68
1 parent 605ce3c commit 624aef9

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717

1818
package org.apache.fontbox.util.autodetect;
1919

20-
import java.io.BufferedReader;
2120
import java.io.File;
22-
import java.io.IOException;
23-
import java.io.InputStreamReader;
24-
import java.nio.charset.StandardCharsets;
2521
import java.util.List;
2622

2723
import org.apache.logging.log4j.Logger;
@@ -36,32 +32,6 @@ public class WindowsFontDirFinder implements FontDirFinder
3632

3733
private static final Logger LOG = LogManager.getLogger(WindowsFontDirFinder.class);
3834

39-
/**
40-
* Attempts to read windir environment variable on windows (disclaimer: This is a bit dirty but seems to work
41-
* nicely).
42-
*/
43-
private String getWinDir(String osName) throws IOException
44-
{
45-
Process process;
46-
Runtime runtime = Runtime.getRuntime();
47-
String cmd;
48-
if (osName.startsWith("Windows 9"))
49-
{
50-
cmd = "command.com";
51-
}
52-
else
53-
{
54-
cmd = "cmd.exe";
55-
}
56-
String[] cmdArray = { cmd, "/c", "echo", "%windir%" };
57-
process = runtime.exec(cmdArray);
58-
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
59-
process.getInputStream(), StandardCharsets.ISO_8859_1)))
60-
{
61-
return bufferedReader.readLine();
62-
}
63-
}
64-
6535
/**
6636
* {@inheritDoc}
6737
*
@@ -86,9 +56,9 @@ public List<File> find()
8656
{
8757
try
8858
{
89-
windir = getWinDir(osName);
59+
windir = System.getenv("windir");
9060
}
91-
catch (IOException | SecurityException e)
61+
catch (SecurityException e)
9262
{
9363
LOG.debug("Couldn't get Windows font directories - ignoring", e);
9464
// should continue if this fails

0 commit comments

Comments
 (0)