Reputation: 65
I have Java Code that launch process of WinSCP tool and connects to a Unix machine and then call a xxxx.exe located on the Unix machine.
The problem is that xxxx.exe accepts a parameter of a type File. So I need to upload this to the remote machine and then passed to the xxxx.exe.... that is failing and I'm trying to avoid the temporary folders as possible.
small Code
Process p = Runtime.getRuntime().exec("rTool\\WinSCP.com /script=folder\\code.txt < C:\\FILESTOUPLOADS\\upload1.txt" );
The login information goes in code.txt
as supported by WinSCP.com
Upvotes: 0
Views: 1125
Reputation: 53694
file redirection (i.e. the "<" symbol) is handled my the command processor, which Runtime.exec()
does not use. As mentioned in comments already, first use the String[] version of exec so that you don't have issues with command parsing. second, you need to invoke the command processor to handle the file redirection (e.g. using "cmd.exe /k"), or handle it yourself in java.
Upvotes: 1
Reputation: 19185
Why not use ProcessBuilder
to change working directory and set path of the file from that directory
public ProcessBuilder directory(File directory)Sets this process builder's working directory. Subprocesses subsequently started by this object's start() method will use this as their working directory. The argument may be null -- this means to use the working directory of the current Java process, usually the directory named by the system property user.dir, as the working directory of the child process.
Parameters: directory - The new working directory Returns: This process builder
Upvotes: 0