Execute shell command in c++

I have a question regarding executing shell commands in c++. I'm building an application in winforms, vs 2008. My application has a button, when clicked should decode a binary file to a .csv file. I can decode files by first going to the right directory (cd Test_Copy2) and then execute a command in the command prompt (java -jar tool.jar -b x.fit x.csv). I tried a lot of different stuff but unfortunately got none to work!

I tried using:

system, _popen, ShellExecute(NULL, L"open", L"C:\\WINDOWS\\system32\\cmd.exe ", L"java -jar Tool.jar -b x.fit x.csv", L"C:\\Test_Copy2", SW_SHOWNORMAL)

Can anyone please provide me with an example on how to do that? I dont know where I'm going wrong, most of the time the command prompt opens but no command is executed!

-------------Problems Reply------------

If you really want to run the jar in a cmd.exe instance, you need to add one of the correct command line switches to cmd.exe for it to work the way you want it to:

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains

For instance, your command string should be:

C:\\WINDOWS\\system32\\cmd.exe /c java -jar Tool.jar -b x.fit x.csv

You can use the system() function to execute shell commands. For example: system("DIR") executes the DIR command in the CMD shell. The default directory at the start is the directory you're .exe file is located. 'system("PAUSE")` executes the PAUSE command. The command/s you wannt to execute should be passed as a constant string to the function.


For you paritcular program the syntax (IMO) would be:

system("java -jar Tool.jar -b x.fit x.csv")

Category:c# Views:1 Time:2011-08-29

Related post

  • Execute shell command from within MySQL client? 2009-05-30

    In oracle database, command "host" can be used to run bash command from database command window. Is there a equivalent command as "host" in mySql? --------------Solutions------------- You can use the system command. system command, \! command Execute

  • Executing shell commands using PHP, e.g. shell_exec() etc., on a remote host? 2010-09-19

    Is it possible to execute shell commands on a remote computer (not localhost)? For instance things like $output = shell_exec("unzip filename.zip"); You can assume that you have the login credentials of a user account on the remote machine, as well as

  • CTS_ERROR >>> Failed to execute shell command am instrument 2010-11-29

    Using the Android 2.2, API-8, SDK-r7 along with CTS-2.2_r4 suite. Updated the SDK_ROOT environment variable with SDK_r7 tools in “android-cts/tools/startcts” script and the “SDK_ROOT/tools” also included in PATH environment variable. Ran the “android

  • Executing shell command from ruby console returning Permission Denied Error? 2011-03-28

    Getting permission denied error while executing shell command from ruby console. And the same shell command is working from shell. From Shell.. [email protected]:~$ "`grep '^datadir=' /etc/mysql/my.cnf | cut -f 2 -d '='`/db_backups" bash: /db_b

  • How to execute shell command in C? 2011-05-12

    I am having problems executing the shell commands in C. I want to execute a shell command in C then capture the output of shell command and process the output further. I used following code to perform the functionality. But, the issue is when the she

  • How to execute shell commands in android? 2011-07-31

    I am trying to execute shell command through my code for adding entry in Iptables. The following is my piece of code private void createShellCommand(String uidValue_param, String interface_param) { // TODO Auto-generated method stub StringBuilder cmd

  • python: os.system does not execute shell command 2012-03-02

    I need to execute shell command in python program (I have ubuntu). More specifically I want to create graph using graphviz in python script. My code is os.system("dot -Tpng graph.dot -o graph.png") It does not work, but if I just type "dot -Tpng grap

  • php executing shell command gives random output in only in heavy use mode 2012-03-28

    Please help me with this issue that I am facing on production server. I launched an application that saves images in a directory only after checking that it does not already exist. To check if it already exists I used the following command find $file

  • Groovy executing shell commands 2008-10-01

    Groovy adds the execute method to String to make executing shells fairly easy; println "ls".execute().text but if an error happens, then there is no resulting output. Is there an easy way to get both the standard error and standard out? (other than c

  • Executing shell command from MySQL 2008-11-14

    I know what I'm looking for is probably a security hole, but since I managed to do it in Oracle and SQL Server, I'll give it a shot: I'm looking for a way to execute a shell command from a SQL script on MySQL. It is possible to create and use a new s

  • PHP exec() will not execute shell command when executed via browser 2009-02-11

    I have a certain PHP script that calls exec() to execute a command to convert a PDF to JPG. This command works fine in bash. To preempt your initial troubleshooting guesses, note the following: safe_mode = Off Permission on the directory containing t

  • vim: execute shell command without filtering 2009-08-06

    I want to select a block of text (eg. V%) and use the text as input to a shell command (eg. wc or pbcopy) - but I DON'T want to alter the current buffer - I just want to see the output of the command (if any) the continue editting without any changes

  • How to execute shell command in Javascript 2009-12-10

    I want to write a javascript function which will execute the system shell commands (ls for example) and return the value. How do I achieve this? --------------Solutions------------- What if the client you are executing this javascript is running Wind

  • Executing shell commands from Java 2010-06-17

    I'm trying to execute a shell command from a java application, on the GNU/Linux platform. The problem is that the script, that calls another java application, never ends, although it runs successfully from bash. I tried to debug it: (gdb) bt #0 0xb77

  • I want to execute shell commands from maven's pom.xml 2010-08-16

    I want to execute linux shell commands with maven. Here is what I tried: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1.1</version> <executions>

  • executing shell command in background from script 2010-09-10

    how can I execute a shell command in the background from within a bash script, if the command is in a string? For example: #!/bin/bash cmd="nohup mycommand"; other_cmd="nohup othercommand"; "$cmd &"; "$othercmd &"; this does not work -- how c

  • C# Web service: want to execute shell command as Admin (or higher priv.) 2010-12-08

    I have a web service which needs to execute a command on the server it's sitting on. Specifically, I'm running the "net start [certain service]" command. The problem lies in the permissions... the web service is running as NETWORK SERVICE, which does

  • Ruby: execute shell command 'echo' with '-n' option 2011-02-20

    I'd like to run the following shell command from Ruby, which copies a string into the clipboard (on OS X), 'n' is suppressing the line break after the string caused by echo: echo -n foobar | pbcopy —> works, fine, now the clipboard contains "fooba

  • Executing shell command and reading its output on a C program 2011-03-12

    I am trying to create a function which takes a shell command as an argument , uses fork to spawn a new process which executes the command. I also want to redirect the standard output of the command so the caller of the function can read it using a FI

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.141 (s). 11 q(s)