0

i m trying to run a mp3 file on dosbox plateform by c .i put the following code in to the batch file
start c:\xyz.mp3 and trying to call this as system("c:/a.bat"), the system funtion is returing 0 but it is not running it. But the same code working well on Cmd . i m using win 7 32 bit..

4
Contributors
10
Replies
34
Views
3 Years
Discussion Span
Last Post by cgeier
1

The following works for me:

#include <cstdlib>

//use 8.3 filename and directory name format
//my file is in "c:\batch scripts\startmp3.bat"

//To get the 8.3 directory name:
//in cmd window run > dir "c:\" /x | find /i "batch scripts"


system("c:\\batchs~1\\startmp3.bat"); //make sure to escape '\'

//should also be able to use:
//system("c:/batchs~1/startmp3.bat");

See How Windows Generates 8.3 File Name from Long File Names

The important thing is to use 8.3 (DOS) filenames.

Edited by cgeier: update code

1

Note that system() returns a program status code. It is good practice to use this value for error handling.

Votes + Comments
but i m still searching for the solution
0

when i m using system("c:\xyz.bat"); it is returning zero and print a message "Illegal commanad:c:\xyz.bat". But on using system("c:/xyz.bat"); it is not showing illegal command statement but also not running.......

0

Try this:

int Status = system("cmd.exe /c c:/xyz.bat");

Or on Windows 64 bit:

int Status = system("%windir%\\Sysnative\\cmd.exe /c c:/xyz.bat");

I'm not on Windows so I can't test this for you. Can't hurt.

Reference

1

I discovered another solution that lets you avoid 8.3 filenames. Use double-quotes. But you need to escape them with a '\'.

#include <cstdlib>

int returnVal = 0;

//need to put quotes if dir or filename contains spaces
//need to escape quotes
returnVal = system("\"c:/batch scripts/startmp3.bat\"");

if (returnVal != 0)
{
    printf("An error occurred while running the command.  (%i)\n",returnVal);
}//if
else
{
    printf("Command executed successfully.\n",returnVal);
}//else

return returnVal;

Here is another resource that may be of use:
How to spawn console processes with redirected standard handles

Edited by cgeier: update code

Votes + Comments
its not showing any illegal command and system() returing 0, but the problem is that my mp3 file is not playing..... on cmd same bath file work good and play mp3
0

If using '\', you may need to escape it. So use system("c:\\xyz.bat"); instead of system("c:\xyz.bat");

0

Can you post your code? Also, what program are you trying to use to play the mp3? Check the Windows default: Control Panel (View by: Large icons) => Default programs => Associate a file type or protocol with a program. Look for "mp3." What is the current default?

0

i m just trying to invoke a batch file by using system() function. Batch file containing start c:\abc.mp3 and i m passing this batch file to system("c:/xyz.bat"); both mp3 and batch file in the same directory , system is returning 0 but the mp3 file is not playing.....

0

Sounds like the console window is closing and killing the mp3. Add a PAUSE in the batch file after the line that plays the mp3 to keep the console window open while the mp3 plays.

0

I know what you're trying to do. But I want to see how you are doing it, because obviously what you are doing isn't working for you. Without the code I can't help any further. Also include the batch (.bat) file. What C compiler are you using? Also a screen shot of the error may be helpful.

Edited by cgeier: comment

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.