aspose file tools*
The moose likes I/O and Streams and the fly likes ProcessBuilder - file types to be executed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "ProcessBuilder - file types to be executed" Watch "ProcessBuilder - file types to be executed" New topic
Author

ProcessBuilder - file types to be executed

Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Hello,


I would like to know if i can run any file type at ProcessBuilder class. I ever tried run stuff "notepad.exe" or "calc.exe" and runs fine, but i entered with full directory path at ProcessBuilder.directory and does not run. My code:




This code has a extension "wav" but i ever tried others and does not run.

Thank you in advance,

Marco Antônio Cintra
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

This has nothing to do with process builder. It's because .wav files are not executable. Processbuilder, like everything else, including Windows itself, can only execute files that are executable.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

Jeff is right. Fortunately, there is a way to execute any file with its associated program:
There is also an even easier way, and that is with java.awt.Desktop and its open method. This will not only work on Windows but also on all other operating systems that support it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Hello again,

Guys, i think there's error in syntax, because i changed the extension to ".exe" and continues ocurring error. My code modified:

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

No.

Just changing the file extension to .exe doesn't magically make it an executable file.
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Guys, the solution of Rob worked. There is a need to insert the code Rundll32.dll. I was thinking with that weird because my code I could not open a text file "txt" common.
I was also thinking that any. Exe file was an executable file ... I still do not quite understand, but okay ...

Thank you all.
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Jeff Verdegan wrote:No.

Just changing the file extension to .exe doesn't magically make it an executable file.


Why any ".exe" is not a executable?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Marco Antonio Cintra wrote:
Jeff Verdegan wrote:No.

Just changing the file extension to .exe doesn't magically make it an executable file.


Why any ".exe" is not a executable?


Whether or not a file is exectuable--that is, can be executed--depends on the contents of the file, not the extension. The convention is that executable files on Windows end in .exe, but just changing that extension doesn't magically make the file able to be executed. Imagine you have a file named fred.txt containing "My name is Fred." Now change the name to fred.exe. Would you expect the file to be able to be executed?
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Jeff Verdegan wrote:
Marco Antonio Cintra wrote:
Jeff Verdegan wrote:No.

Just changing the file extension to .exe doesn't magically make it an executable file.


Why any ".exe" is not a executable?


Whether or not a file is exectuable--that is, can be executed--depends on the contents of the file, not the extension. The convention is that executable files on Windows end in .exe, but just changing that extension doesn't magically make the file able to be executed. Imagine you have a file named fred.txt containing "My name is Fred." Now change the name to fred.exe. Would you expect the file to be able to be executed?


I understand... but there's a strong relation with the rundll32.dll, doesn't? I say, if you code "notepad.exe" without the rundll32 code, it runs, but if you code "fred.txt" it does not runs.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Marco Antonio Cintra wrote:
I understand... but there's a strong relation with the rundll32.dll, doesn't? I say, if you code "notepad.exe" without the rundll32 code, it runs, but if you code "fred.txt" it does not runs.


And your point is...?
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Jeff Verdegan wrote:
Marco Antonio Cintra wrote:
I understand... but there's a strong relation with the rundll32.dll, doesn't? I say, if you code "notepad.exe" without the rundll32 code, it runs, but if you code "fred.txt" it does not runs.


And your point is...?


My point is, without the rundll32.dll, its possible only runs native processes, like "notepad.exe", "calc.exe"...

Thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Marco Antonio Cintra wrote:
Jeff Verdegan wrote:
Marco Antonio Cintra wrote:
I understand... but there's a strong relation with the rundll32.dll, doesn't? I say, if you code "notepad.exe" without the rundll32 code, it runs, but if you code "fred.txt" it does not runs.


And your point is...?


My point is, without the rundll32.dll, its possible only runs native processes, like "notepad.exe", "calc.exe"...

Thanks


Okay, I have no argument with that. I don't know the details of what's required to execute something in Windows. But I wasn't trying to answer that question. I was merely pointing out that, contrary to your apparent expectations, you can't just execute any old file, and simply changing the file extension to .exe doesn't make a non-executable file into an executable one.
Marco Antonio Cintra
Greenhorn

Joined: Nov 19, 2011
Posts: 8

Jeff Verdegan wrote:
Marco Antonio Cintra wrote:
Jeff Verdegan wrote:
Marco Antonio Cintra wrote:
I understand... but there's a strong relation with the rundll32.dll, doesn't? I say, if you code "notepad.exe" without the rundll32 code, it runs, but if you code "fred.txt" it does not runs.


And your point is...?


My point is, without the rundll32.dll, its possible only runs native processes, like "notepad.exe", "calc.exe"...

Thanks


Okay, I have no argument with that. I don't know the details of what's required to execute something in Windows. But I wasn't trying to answer that question. I was merely pointing out that, contrary to your apparent expectations, you can't just execute any old file, and simply changing the file extension to .exe doesn't make a non-executable file into an executable one.


Yeah, i understand.

Thank you, guy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ProcessBuilder - file types to be executed