Captcha142 wrote:Is there a way to write a batch file and then associate the file type with the batch file so that the batch file runs commands with the selected file name
I know how to associate file types, it's the batch file part I don't understand.
The goal of this is to run the following commands:
@echo off
javac (name of run file).java
java (name of run file)
Is this possible?
EDIT:
Alternatively, could I simply run the batch and pass a command to it.
eg. (where the batch file name is test.bat)
C:\System32>test | (name of file)
I'm confused by your request, so I think I'll break it down.
Is there a way to write a batch file
Yes, you use these weird things, that I have named myself, which I call "senders". You send the output of a command to a file.
Will create a file named "test.txt" with the text "I love pie" inside.
associate the file type with the batch file
... Usually if you write a file, you should know the file type. I'm not 100% sure that there isn't a Batch command for this, but I don't think there is. So you can always just mix it with JScript. Here's an example:
Code: Select all
@echo off
set fname=bob.txt
echo.var file = new ActiveXObject("scripting.filesystemobject").getfile("%fname%");WScript.StdOut.Write(file.type);>~tmp.jse&cscript //nologo ~tmp.jse&ping 0 -n 1 > nul & del ~tmp.jse > nul
Now if you want to send the file type to a variable, use:
Code: Select all
@echo off
set fname=bob.txt
echo.var file = new ActiveXObject("scripting.filesystemobject").getfile("%fname%");WScript.StdOut.Write(file.type);>~tmp.jse
for /f "tokens=*" %%a in ('cscript //nologo ~tmp.jse') do (
set ftype=%%a
)
del ~tmp.jse
echo The file type is: %ftype%
pause
I like my method because instead of just giving you the extension, this will actually tell you what the file type is named. Such as, if I used "vp.com" instead of "bob.txt", it would say:
the batch file runs commands with the selected file name
You always know the file name already in codes. Such as if you write it or read it, you need the name. If you want to make the prompt use "open with", it sends the name of the file it was opened with to "%1".
Bob D wrote:The START command can execute commands external to the current window. It can also name files which will be processed by a file extension association. You can execute them and wait for them to finish or simply launch them and forget them. Look at START /?
I used the following in a shortcut with the intent to lift the execution priority. I launch a cmd.exe, then issue the START command to start a batch file at high priority. You could use it within a batch file to do what you want. Is the java an example? If you can run it via a command line then you should be able to do it. See CMD /? and START /? for more detail.
C:\Windows\System32\cmd.exe /C start /realtime /b c:\bootlog\pcinfo.bat 45 0d
First of all, why the freaking pickle are you writing out the full path of a file that's already in your system32 folder?!?!?!?!?!
And second of all, I don't even have bootlog/pcinfo.bat on my PC! So I don't even see your point because any newbie can't test it!
Also, why "/realtime"? It usually works okay without that...
So it is unhelpful.