what i wanted to do is to get all the installed applications in a computer and ihave decided to use the /output command of the command prompt using java. my code was working properly with this line of code in my computer:
Process proc = rt.exec("wmic /output:C:\\Users\\Public\\Documents\\list.csv product get name,version /format:csv ");
however, when i try to run the program in another computer, i encounter the "Invalid XSL format or file name" error. I tried reading other problems and i added this line of code before the code above:
proc2 = rt.exec("xcopy /y C:\\Windows\\System32\\wbem\\en-US\\*.xsl C:\\Windows\\System32\\");
but still nothing happened. the error is still there. anyone who can help me with this problem?
This is a bug in Windows 7 WMIC. When you use (for example) Dutch regional settings in an English Windows installation, WMIC searches for the xsl files inside C:\Windows\System32\wbem\nl-NL, instead of C:\Windows\System32\wbem\en-US where they are.
Workarounds:
Copy or move the C:\Windows\system32\wbem\en-US\*.xsl files up into the C:\Windows\system32\wbem\ folder.
Change your regional settings to match your Windows language version, log out and back in.
Specify the full path: WMIC process get /format:"%WINDIR%\System32\wbem\en-US\csv".
Related
I have been doing research on why Java keeps closing immediately upon opening it. I am on Windows 10 and running on a 64 bit. I did install the correct Java download for Windows 64 bit. I have uninstalled it and installed it about four times but nothing seemed to help. I also double checked to see if it was up to date and it was at the latest version. I am unsure why this problem is occurring.
Any advice?
You should not directly run java.exe from the jdk bin path. You must do it in command prompt. The main thing is if you are not using any IDE and trying to write your code in any editor then manually run it. then you have to set java path as environment variable.
Watch this video to do that https://www.youtube.com/watch?v=l1VxWWubxFo .
Then write a simple java program , save it with .java extension.
Then open cmd there where you have written the program by holding shift key and right click on the file explorer, you will see a option like open command window here.
Then write javac <your java file name with .java extension>.
Then write java <your class name in the program>. Ignore these < > angle quotes
I have been trying to get ANTLR to work all day. I have used several websites including antlr.org, numerous StackOverflow queries and the textbook by Terence Parr. I am on a Windows 7 machine (work machine, can't change to Linux) but I have tried this on both CommandPrompt and Cygwin, with the same result.
No matter what I do, when it comes time to use the grun file, I always come up with the same error in the end:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I have the most recent versions of the JRE and JDK on my computer, as well as the most recent version of cygwin.
I can run the batch files for grun and antlr4 from anywhere, so I'm strongly guessing my path is set correctly. I can run antlr4.bat with absolutely no issue. It creates every file the text book says I should see:
Hello.g4 HelloBaseListener.java HelloLexer.tokens HelloParser.java Hello.tokens HelloLexer.java HelloListener.java
I can run javac on those files and it generates various CLASS files:
HelloBaseListener.class HelloLexer.class HelloListener.class HelloParser$RContext.class HelloParser.class
But then, when I try to run grun on it, I get this:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I've tried several combinations of commands to use the grun file, but the one it says to use in the book is:
grun.bat Hello r -tree
I've also changed the .bat file with grun several times, just to experiment, using different combinations in the books and on the sites, but I always come back to this:
java org.antlr.v4.runtime.misc.TestRig %*
That is what my boss told me to use, and it works for him.
Use this in your grun.bat command
java org.antlr.v4.gui.TestRig %*
I had the same problem, there is actually already a thread with the solution here --> antlr4-Can't load Hello as lexer or parser
The first part of the message "Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically" just means that the TestRig order is saved to another location, it works anyway but I changed my batch data accordingly and did not get the Warning anymore. The second part of the message is the actual problem (see link). In my case I forgot the "." (dot) in my CLASSPATH in Windows.
I've been googling for the better part of 4 hours and nothing I've tried has had any effect. This is your typical JAVA_HOME while configuring android studio on a machine for the first time problem it would appear. I've added literally everything to environment variables and path that I can think of. I've tried reinstalling JRE/JDK/Android Studio many many times. I've tried deleting .android and ..\Local\Temp items. I've tried running android.bat as admin. Nothing helps.
I can run find_java64.exe directly and it actually gives me the correct path, but in the batch file it says it can't find that file. The only thing I noticed is that it says "...Local\Android\sdk\tools\lib\\find_java64.exe" -s with two slashes instead of one after lib. That seems strange but not like it should cause it to not find it... and if I copy-paste the entire path with executable from the error line into command prompt (including the two slashes) it DOES show the JDK location correctly.
Why does the script not work if the line works in isolation? I can't do anything if this batch file isn't going to work.
Edit: I've been trying some more today. The core issue seems to be that when batch files are attempting to run other scripts/executables, windows always throws a is not recognized as an internal or external command, operable program or batch file." error. I've been tracing this through script after script from android.bat to find_java.bat. If I manually execute the command the batch file is trying to execute in command prompt, it works fine, but the batch file says it's wrong. Another suspicious thing seems to be that I cannot double click on ANY batch files in the computer. I can only open them as admin or from command prompt. Starting to think this is a very computer-specific problem.
If anybody else is seeing this, there's a real problem on your system when you can't launch a BAT file by double clicking it.
Something you could test on your machine is drop into a cmd shell then using the ftype and assoc builtins to check these are the defaults:
➜ ~\scoop\apps\android-sdk\current\tools\lib $ cmd
Microsoft Windows [Version 10.0.19041.572]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\Users\cwalsh\scoop\apps\android-sdk\current\tools\lib>assoc .bat
.bat=batfile
C:\Users\cwalsh\scoop\apps\android-sdk\current\tools\lib>ftype batfile
batfile="%1" %*
If it's still broken you might need to dive into the registry and figure out why the .BAT file extension has a different program associated with it.
By running the same command from the Eclipse and from the command line I get 2 different results:
With Eclipse everything works fine, however with the command line I get the following error message:
PosixThing.java:17: error: error while writing PosixThing: PosixThing.class (Permission denied)
This error message does not appear if I run "sudo javac PosixThing.java".
As it if was not strange enough, the same code with a different file located in the same directory (Desktop) does not give me any problem. (I am talking about mere txt files just to test the PosixFilePermissions function).
I checked the file permissions and everything is -rw -rw -rw As well as the others'. Do not know why it happens only with that specific file.
Running on Ubuntu 11.10 jdk 1.7.
Any suggestion to what it might be?
It sounds like a file / filesystem permissions problem of some kind:
Check the owner, group and permissions for the file, and all directories on the file pathname.
Check that you are running Eclipse and your command shell as the same effective user.
Check that you are not attempting to write to some kind of "funky" file system; e.g. a Windows file system mounted on Linux, or a FUSE file system of some kind.
If you've got SELinux enabled, check that's not causing the problem. (That's unlikely.)
It is also possible that you are running different releases / versions of Java in the two contexts, or even that Eclipse's file system cache is out of sync. (It is not clear to me what contexts the code is actually running in.)
I added a value at:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
That looks like this:
Value Name: LDE
Value Data: "java -jar C:\LDE\lde.jar"
Really with the quotes (Because all the others where also with quotes). After adding this, I restarted my computer, but it didn't start automatically.
Will wrapping my jar in an exe help?
I'm running Windows 7.
Any help?
Thanks in advance.
Update:
When I remove the quotes, it works. But now there is appears also a terminal, which I don't need...
A couple of things to note here, concerning the two different issues in the problem:
Format of Windows Run keys
From the Microsoft Windows XP knowledge base:
Run keys cause programs to
automatically run each time that a
user logs on. The Windows XP registry
includes the following four Run keys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
Each of these keys has a series of
values. The values allow multiple
entries to exist without overwriting
one another. The data value for a
value is a command line.
Note the emphasis on the last line. The moment quotes are used, the command is bound to fail execution in the same manner it fails as if executed from a command prompt.
Also, note that the above approach is for Windows XP and does hold good for Windows 7. More details can be found in this Microsoft Technet article on the options available in Windows 7.
The javaw vs java application launcher
Once the java process can be initialized at Windows startup, one will get a console window that continues to stay around until the process is terminated. This occurs if the java executable is utilized to initialize the application.
From the technotes of the java application launcher:
The javaw command is identical to
java, except that with javaw there is
no associated console window. Use
javaw when you don't want a command
prompt window to appear. The javaw
launcher will, however, display a
dialog box with error information if a
launch fails for some reason.
Therefore, if you wish to avoid opening a console window for the Java process, you ought to use the javaw executable.
This is very simple. You will find the startup folder in the C:/Documents and Settings/AllUsers/YourUserName/StartUp. It will be on similar kind of path just check it. Then just paste your jar file in that folder and it will work nice. Remember that you put the jar file in the startup folder of your user name folder. You may find that this folders might be hidden so just check it out. If you find this answer useful vote it. Enjoy.....