Issues trying to use FUSE on Bluemix - ibm-cloud

I was looking for a way to add a remote file system accessible into Bluemix. In this post I was told to use cflinuxfs2 stack which is supported in last versions of Cloud Foundry.
I was able to execute mkdir command for the mount point from my Java app and execute sshfs command but this last one fails with: "read: Connection reset by peer".
The point is that the same commands used in a Linux box at home work fine so I understand the command, the ssh key and the know hosts files are ok.
This is the piece of Java EE code deployed into Liberty runtime in Bluemix:
String s = null;
Process p = null;
BufferedReader br = null;
try
{
p = Runtime.getRuntime().exec("mkdir -p /home/vcap/misc");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command mkdir with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("sshfs ibmcloud#129.41.133.34:/ /home/vcap/misc -o IdentityFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts -o idmap=user -o compression=no -o sshfs_debug");
br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command sshfs with exit: " + p.exitValue());
p.destroy();
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(br != null)
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
Referenced files in the commands are included in the EAR file and pushed as part of the app. I can see them and their content browsing the file system from Bluemix dashboard.
Browsing the web, I found tons of post about error message: "read: Connection reset by peer" but it seems they don't apply to my case or they are related to firewalls and config files I have no access in Bluemix. And as I said, the same two commands executed in my linux box at home work fine.
Any idea or recommendation to get it working? Anybody tested this idea before in Bluemix?
Thanks!

Ok, finally I found the reason of the issue with the help of team colleagues. Problem was with permissions of the private ssh key. It has to be 600 and by default it was 644 after the cf push.
So here it is the final code (quick and dirty) that worked, just in case it can be useful to others...
Include into the app the private key and the known_hosts files.
Push the app adding -s cflinuxfs2 parameter.
Execute at runtime startup some code like this:
String s = null;
Process p = null;
BufferedReader br = null;
try
{
p = Runtime.getRuntime().exec("mkdir -p /home/vcap/misc");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command mkdir with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command chmod with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command chmod with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("sshfs ibmcloud#129.41.133.34:/home/ibmcloud /home/vcap/misc -o IdentityFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts -o idmap=user -o compression=no -o sshfs_debug");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command sshfs with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("ls -l /home/vcap/misc");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command ls with exit: " + p.exitValue());
p.destroy();
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(br != null)
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
This snippet should create a folder, mount a remote file system into that folder and list the content of the remote file system.

Related

Why do i keep getting Cannot run program error? [duplicate]

I found several code snippets for running cmd commands through a Java class, but I wasn't able to understand it.
This is code for opening the cmd
public void excCommand(String new_dir){
Runtime rt = Runtime.getRuntime();
try {
rt.exec(new String[]{"cmd.exe","/c","start"});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And I found some other links for adding other commands such as cd
http://www.coderanch.com/t/109753/Linux-UNIX/exec-command-cd-command-java
How to open the command prompt and insert commands using Java?
Can anyone help me to understand how to cd a directory such as:
cd C:\Program Files\Flowella
then run other commands on that directory?
One way to run a process from a different directory to the working directory of your Java program is to change directory and then run the process in the same command line. You can do this by getting cmd.exe to run a command line such as cd some_directory && some_program.
The following example changes to a different directory and runs dir from there. Admittedly, I could just dir that directory without needing to cd to it, but this is only an example:
import java.io.*;
public class CmdTest {
public static void main(String[] args) throws Exception {
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "cd \"C:\\Program Files\\Microsoft SQL Server\" && dir");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) { break; }
System.out.println(line);
}
}
}
Note also that I'm using a ProcessBuilder to run the command. Amongst other things, this allows me to redirect the process's standard error into its standard output, by calling redirectErrorStream(true). Doing so gives me only one stream to read from.
This gives me the following output on my machine:
C:\Users\Luke\StackOverflow>java CmdTest
Volume in drive C is Windows7
Volume Serial Number is D8F0-C934
Directory of C:\Program Files\Microsoft SQL Server
29/07/2011 11:03 <DIR> .
29/07/2011 11:03 <DIR> ..
21/01/2011 20:37 <DIR> 100
21/01/2011 20:35 <DIR> 80
21/01/2011 20:35 <DIR> 90
21/01/2011 20:39 <DIR> MSSQL10_50.SQLEXPRESS
0 File(s) 0 bytes
6 Dir(s) 209,496,424,448 bytes free
You can try this:-
Process p = Runtime.getRuntime().exec(command);
If you want to perform actions like cd, then use:
String[] command = {command_to_be_executed, arg1, arg2};
ProcessBuilder builder = new ProcessBuilder(command);
builder = builder.directory(new File("directory_location"));
Example:
String[] command = {"ls", "-al"};
ProcessBuilder builder = new ProcessBuilder(command);
builder = builder.directory(new File("/ngs/app/abc"));
Process p = builder.start();
It is important that you split the command and all arguments in separate strings of the string array (otherwise they will not be provided correctly by the ProcessBuilder API).
Here is a more complete implementation of command line execution.
Usage
executeCommand("ls");
Output:
12/27/2017 11:18:11:732: ls
12/27/2017 11:18:11:820: build.gradle
12/27/2017 11:18:11:820: gradle
12/27/2017 11:18:11:820: gradlew
12/27/2017 11:18:11:820: gradlew.bat
12/27/2017 11:18:11:820: out
12/27/2017 11:18:11:820: settings.gradle
12/27/2017 11:18:11:820: src
Code
private void executeCommand(String command) {
try {
log(command);
Process process = Runtime.getRuntime().exec(command);
logOutput(process.getInputStream(), "");
logOutput(process.getErrorStream(), "Error: ");
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
private void logOutput(InputStream inputStream, String prefix) {
new Thread(() -> {
Scanner scanner = new Scanner(inputStream, "UTF-8");
while (scanner.hasNextLine()) {
synchronized (this) {
log(prefix + scanner.nextLine());
}
}
scanner.close();
}).start();
}
private static SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss:SSS");
private synchronized void log(String message) {
System.out.println(format.format(new Date()) + ": " + message);
}
My example (from real project)
folder — File.
zipFile, filesString — String;
final String command = "/bin/tar -xvf " + zipFile + " " + filesString;
logger.info("Start unzipping: {} into the folder {}", command, folder.getPath());
final Runtime r = Runtime.getRuntime();
final Process p = r.exec(command, null, folder);
final int returnCode = p.waitFor();
if (logger.isWarnEnabled()) {
final BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
logger.warn(line);
}
final BufferedReader is2 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = is2.readLine()) != null) {
logger.warn(line);
}
}
The easiest way would be to use Runtime.getRuntime.exec().
For example, to get a registry value for the default browser on Windows:
String command = "REG QUERY HKEY_CLASSES_ROOT\\http\\shell\\open\\command";
try
{
Process process = Runtime.getRuntime().exec(command);
} catch (IOException e)
{
e.printStackTrace();
}
Then use a Scanner to get the output of the command, if necessary.
Scanner kb = new Scanner(process.getInputStream());
Note: the \ is an escape character in a String, and must be escaped to work properly (hence the \\).
However, there is no executable called cd, because it can't be implemented in a separate process.
The one case where the current working directory matters is executing an external process (using ProcessBuilder or Runtime.exec()). In those cases you can specify the working directory to use for the newly started process explicitly.
Easiest way for your command:
System.setProperty("user.dir", "C:\\Program Files\\Flowella");
Try this:
Process runtime = Runtime.getRuntime().exec("cmd /c start notepad++.exe");
Once you get the reference to Process, you can call getOutpuStream on it to get the standard input of the cmd prompt. Then you can send any command over the stream using write method as with any other stream.
Note that it is process.getOutputStream() which is connected to the stdin on the spawned process. Similarly, to get the output of any command, you will need to call getInputStream and then read over this as any other input stream.
Stopping and Disabling a service can be done via below code:
static void sdService() {
String[] cmd = {"cmd.exe", "/c", "net", "stop", "MSSQLSERVER"};
try {
Process process = new ProcessBuilder(cmd).start();
process.waitFor();
String line = null;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
line = null;
bufferedReader = null;
Process p = Runtime.getRuntime().exec("sc config MSSQLSERVER start= disabled");
p.waitFor();
bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Enabling and Starting a service can be done via below code
static void esService() {
String[] cmd = {"cmd.exe", "/c", "net", "start", "MSSQLSERVER"};
try {
Process p = Runtime.getRuntime().exec("sc config MSSQLSERVER start= auto");
//Process p = Runtime.getRuntime().exec("sc config MSSQLSERVER start= demand");
p.waitFor();
String line = null;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
line = null;
bufferedReader = null;
Process process = new ProcessBuilder(cmd).start();
process.waitFor();
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Executing command from any folder can be done via below code.
static void runFromSpecificFolder() {
try {
ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", "cd \"C:\\Users\\himan\\Desktop\\Java_Test_Deployment\\jarfiles\" && dir");
//processBuilder.directory(new File("C://Users//himan//Desktop//Java_Test_Deployment//jarfiles"));
processBuilder.redirectErrorStream(true);
Process p = processBuilder.start();
p.waitFor();
String line = null;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
sdService();
runFromSpecificFolder();
esService();
}
You can't run cd this way, because cd isn't a real program; it's a built-in part of the command-line, and all it does is change the command-line's environment. It doesn't make sense to run it in a subprocess, because then you're changing that subprocess's environment — but that subprocess closes immediately, discarding its environment.
To set the current working directory in your actual Java program, you should write:
System.setProperty("user.dir", "C:\\Program Files\\Flowella");
public class Demo {
public static void main(String args[]) throws IOException {
Process process = Runtime.getRuntime().exec("/Users/******/Library/Android/sdk/platform-tools/adb" + " shell dumpsys battery ");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while (true) {
line = in.readLine();
if (line == null) { break; }
System.out.println(line);
}
}
}
The simplest and shortest way is to use CmdTool library.
new Cmd()
.configuring(new WorkDir("C:/Program Files/Flowella"))
.command("cmd.exe", "/c", "start")
.execute();
You can find more examples here.
one of the way to execute cmd from java !
public void executeCmd() {
String anyCommand="your command";
try {
Process process = Runtime.getRuntime().exec("cmd /c start cmd.exe /K " + anyCommand);
} catch (IOException e) {
e.printStackTrace();
}
}
Here the value adder is use of ampersands to batch commands and correct format for change drive with cd.
public class CmdCommander {
public static void main(String[] args) throws Exception {
//easyway to start native windows command prompt from Intellij
/*
Rules are:
1.baseStart must be dual start
2.first command must not have &.
3.subsequent commands must be prepended with &
4.drive change needs extra &
5.use quotes at start and end of command batch
*/
String startQuote = "\"";
String endQuote = "\"";
//String baseStart_not_taking_commands = " cmd /K start ";
String baseStart = " cmd /K start cmd /K ";//dual start is must
String first_command_chcp = " chcp 1251 ";
String dirList = " &dir ";//& in front of commands after first command means enter
//change drive....to yours
String changeDir = " &cd &I: ";//extra & makes changing drive happen
String javaLaunch = " &java ";//just another command
String javaClass = " Encodes ";//parameter for java needs no &
String javaCommand = javaLaunch + javaClass;
//build batch command
String totalCommand =
baseStart +
startQuote +
first_command_chcp +
//javaCommand +
changeDir +
dirList +
endQuote;
System.out.println(totalCommand);//prints into Intellij terminal
runCmd(totalCommand);
//Thread t = Thread.currentThread();
//t.sleep(3000);
System.out.println("loppu hep");//prints into Intellij terminal
}
public static void runCmd(String command) throws Exception {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
}
}

Apache commons net FTP clients hangs unpredictably

We tried all the solutions provided in this post (FTP client hangs) but none of them is working. We are using version 3.6 of commons net. Sometimes it hangs while uploading a file, sometimes will checking existence of a directory. Max. file size is around 400 MB. But sometime it hangs even for a small file size < 1KB. Below is the fragment of code:
public boolean uploadData(String inputFilePath, String destinationFolderName) {
if (StringUtil.isNullOrBlank(inputFilePath) || StringUtil.isNullOrBlank(destinationFolderName)) {
LOGGER.error("Invalid parameters to uploadData. Aborting...");
return false;
}
boolean result = false;
FTPSClient ftpClient = getFTPSClient();
if (ftpClient == null) {
logFTPConnectionError();
return false;
}
try {
loginToFTPServer(ftpClient);
result = uploadFileToFTPServer(ftpClient, inputFilePath, destinationFolderName);
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
return false;
} finally {
try {
logoutFromFTPServer(ftpClient);
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
result = false;
}
}
return result;
}
private FTPSClient getFTPSClient() {
FTPSClient ftpClient = null;
try {
ftpClient = new FTPSClient();
LOGGER.debug("Connecting to FTP server...");
ftpClient.setConnectTimeout(connectTimeOut);
ftpClient.connect(server);
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
LOGGER.error("Could not connect to FTP server. Aborting.");
return null;
}
} catch (Exception e) {
LOGGER.error("Could not connect to FTP server.", e);
return null;
}
return ftpClient;
}
private void loginToFTPServer(FTPSClient ftpClient) throws Exception {
ftpClient.setDataTimeout(DATA_TIMEOUT);
ftpClient.login(ftpUserName, ftpPassword);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
LOGGER.debug("FTP Client Buffer Size Before:" + ftpClient.getBufferSize());
ftpClient.setBufferSize(BUFFER_SIZE);
LOGGER.debug("FTP Client Buffer Size After:" + ftpClient.getBufferSize());
ftpClient.execPBSZ(0);
ftpClient.execPROT("P");
ftpClient.setControlKeepAliveTimeout(300);
LOGGER.debug("Logged into FTP server.");
}
private void logoutFromFTPServer(FTPSClient ftpClient) throws Exception {
LOGGER.debug("Logging out from FTP server.");
ftpClient.logout();
ftpClient.disconnect();
LOGGER.debug("FTP server connection closed.");
}
private boolean uploadFileToFTPServer(FTPSClient ftpClient, String inputFilePath, String destinationFolderName) {
boolean result = false;
String remoteLocationFile;
File ftpFile = new File(inputFilePath);
try (InputStream inputStream = new FileInputStream(ftpFile)) {
String fileName = ftpFile.getName();
remoteLocationFile = (destinationFolderName == null || destinationFolderName.isEmpty())
? ftpFile.getName()
: destinationFolderName + File.separator + fileName;
LOGGER.info("Storing file " + ftpFile.getName() + " of size "
+ ftpFile.length() + " in folder " + remoteLocationFile);
result = ftpClient.storeFile(remoteLocationFile, inputStream);
if(result) {
LOGGER.info("Successfully stored file " + ftpFile.getName() + " in folder " + remoteLocationFile);
} else {
LOGGER.error("Unable to store file " + ftpFile.getName() + " in folder " + remoteLocationFile);
}
return result;
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
}
return result;
}
The application is hosted in apache tomcat 8. What could be other causes of this issue and how should we fix them? This is crucial functionality of our application and we may even consider to use alternate API if that is stable. Please suggest.
Adding ftpClient.setSoTimeout(20000); has fixed the issue.
Adding a enterLocalPassiveMode right before the retreiveFile should solve this issue.
You also need to add
ftpClient.setControlKeepAliveTimeout(300);
or Check this code which will resolve the hanging issue

c# console app as service

Just a simple consloe app that I want to have running as a service at all times, don't have the VB template.
So far I have:
given highestAvailable permission in the manifest, and bound the manifest in properties
right clicked on exe compatibility and selected "run as admin"
opened security settings so "everyone", administrators, services, system, network services, local services and some users all have permission for full access.
successfully added to service list with this code, code is run from separate solution form, also running with manifest and as admin:
private static void cmd_PROMPT(string cmd)
{
ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = #"C:\Windows\System32\cmd.exe";
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.Verb = "runas";
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.CreateNoWindow = true;
cmdStartInfo.Arguments = "/user:Administrator ";
Process cmdProcess = new Process();
cmdProcess.StartInfo = cmdStartInfo;
cmdProcess.ErrorDataReceived += cmd_Error;
cmdProcess.OutputDataReceived += cmd_DataReceived;
cmdProcess.EnableRaisingEvents = true;
cmdProcess.Start();
cmdProcess.BeginOutputReadLine();
cmdProcess.BeginErrorReadLine();
cmdProcess.StandardInput.WriteLine(cmd);
MessageBox.Show(">>" + cmd);
//cmdProcess.WaitForExit();
}
private void button3_Click(object sender, EventArgs e)
{
string s;
string prgmName = "#QU#Service";
string prgmPath = "c:\\#QU#\\aquaService.exe";
string prgmMode = "auto";
s = "sc create " + prgmName + " binpath= " + prgmPath + " DisplayName= \"" + prgmName + "\" start= " + prgmMode;
cmd_PROMPT(s);
}
The app has made it in to the service list in control panel but it is "stopped"... when I click ...action... start service, it tries but fails with error:1053 did not start in timely fashion.
When I use CMD instruction it changes to "starting" in the service list, but then goes right back to stop:
prgmName = "#QU#Service";
prgmPath = "c:\\#QU#\\aquaService.exe";
prgmMode = "auto";
s = "sc start " + prgmName;
cmd_PROMPT(s);
ty Noodles, with your clue I was able to get this code working:
private void button3_Click(object sender, EventArgs e)
{
string s;
string prgmName = "#QU#Service";
string prgmPath = "c:\\#QU#\\aquaService.exe";
string prgmMode = "auto";
string _subKey = "Parameters";
string keyName = "Application";
RegistryKey _baseRegistryKey;
s = "C:\\#QU#\\instsrv.exe " + prgmName + " C:\\#QU#\\srvany.exe";
cmd_PROMPT(s);
s = "sc config " + prgmName + " start=auto "; // boot
cmd_PROMPT(s);
try
{
_baseRegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services", true);
var sk1 = _baseRegistryKey.CreateSubKey(prgmName);
_baseRegistryKey = sk1; sk1 = _baseRegistryKey.CreateSubKey(_subKey);
if (sk1 != null) { sk1.SetValue(keyName.ToUpper(), prgmPath, RegistryValueKind.String); }
}
catch (Exception ee)
{
MessageBox.Show(" " + ee, "Administrator");
}
Thread.Sleep(5000);
prgmName = "#QU#Service";
prgmPath = "c:\\#QU#\\aquaService.exe";
prgmMode = "auto";
s = "sc start " + prgmName;
cmd_PROMPT(s);
}

tshark command line to convert a wireskark pcap file to a text file

I am trying to use tshark command line to convert a wireskark pcap file to a text file. everything looks right. But I get no output and no errors
public void convertPcapToTxt( ) {
try {
// setting output and input file names
String resultfile = "C:\\MY.txt";
String pcapfile = "C:\\MY.pcap";
Runtime rt = Runtime.getRuntime();
// create output
PrintStream out = new PrintStream(resultfile);
// set command line
Process proc = rt.exec("tshark.exe -V -r " + pcapfile);
//output to file
BufferedReader stdInput = new BufferedReader
(new InputStreamReader(proc.getInputStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
out.println(s);
}
//close output
out.close();
} catch (IOException io) {
io.printStackTrace();
}
}
public void convertPcapToTxt(File file, String pcapfile) {
try {
PrintStream out = new PrintStream(new FileOutputStream(file));
Runtime rt = Runtime.getRuntime();
String commands = "tshark.exe -V -r \"" + pcapfile + "\"";
Process proc = rt.exec(commands);
BufferedReader stdInput = new BufferedReader
(new InputStreamReader(proc.getInputStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
out.println(s);
}
out.close();
} catch (IOException io) {
io.printStackTrace();
}
}

Incorrect syntax near the keyword 'to' in c# database backup

string sql = "BACKUP DATABASE" + comboBox1.SelectedText.ToString() +
" to disk = '" + textBox1.Text.ToString() + "'\'" +
comboBox1.SelectedText+"'.bak";
try
{
if (!string.IsNullOrWhiteSpace(textBox1.Text))
{
SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Anjum-Dar\Documents\Visual Studio 2012\managerecord\managerecord\recordemanage.mdf;Integrated Security=True");
con.Open();
string sql = "BACKUP DATABASE" + comboBox1.SelectedText.ToString() + " to disk = '" + textBox1.Text.ToString() + "'\'" + comboBox1.SelectedText + "'.bak";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Successfully ");
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}