Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ProcessBuilder - file types to be executed

 
Marco Antonio Cintra
Greenhorn
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20496
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marco Antonio Cintra
Greenhorn
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

Just changing the file extension to .exe doesn't magically make it an executable file.
 
Marco Antonio Cintra
Greenhorn
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
Firefox Browser MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic