LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   in Pascal: how to exec a program, discard text output or send to text file (https://www.linuxquestions.org/questions/programming-9/in-pascal-how-to-exec-a-program-discard-text-output-or-send-to-text-file-550144/)

Valkyrie_of_valhalla 04-30-2007 10:43 AM

in Pascal: how to exec a program, discard text output or send to text file
 
I'm trying to create a program in windows that executes mplayer.exe to play a file, and either discards the output (an equivalent to Linux's "mplayer music.mp3 > /dev/null") or sends it to a file.
What I've tried so far, is this test program:
Code:

Program test;
uses dos,crt;
begin
clrscr;
exec('mplayer.exe',' mymusic.mp3 > logfile.txt');
end.

It plays the file, but it displays a series of info on the screen.
Now, if I open a command prompt and enter "mplayer.exe mymusic.mp3 > logfile.txt", it does exactly what I want to: sends all that info about the mp3 to logfile.txt, without displaying anything on the screen.

In the big picture: I want to write a guitar tuning/learning program, that uses mplayer to play the sounds, and that's why I want it not to display anything.

So, how can I play the file, without recieving any text output from the program? (either mplayer, or if anyone can suggest another command-line GPL-ed version wav/midi player)
If anyone has any other ideas on how I can do this (besides coding the media player program my self, as I don't have enough skills to do that), that will be also welcomed.

Thanks for reading, and sorry for the newbie question. Any info/suggestion is welcomed.

Guttorm 04-30-2007 12:33 PM

Hi

I remember a bit about DOS but I'm good at forgetting. I think devices was name and : - so maybe try:
exec('mplayer.exe',' mymusic.mp3 > nul:');

Think there was a null device, but i'm not sure the name was "nul:".

Edit:
Was not so good at forgetting after all :)

Quote:

Microsoft Windows XP [Versjon 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corporation

C:\Documents and Settings\Guttorm>echo test > nul:
No output :)

Valkyrie_of_valhalla 04-30-2007 01:11 PM

Thanks for the quick reply.
Indeed, it is "nul:". Thanks for telling me about it, it's good to know I won't have to complicate my program with useless textfiles.

It works ok from a command prompt, but, as with the output from a file, doesn't work within the program.... It still outputs the text to the main screen...

I guess I got the exec function wrong? It seems to ignore the "> whatever " bit at the end...

Any ideas on this?

Guttorm 04-30-2007 03:15 PM

Maybe
exec("mplayer.exe mymusic.mp3 > nul:");
I don't know why it was split up?

edit:
I think I recall something like
exec(getenv("COMSPEC")+" /c "+args)

Good luck with the program!

Valkyrie_of_valhalla 05-01-2007 04:00 AM

Thanks, I half-got it now...

It's split in two because the syntax is:
exec('program name','arguments to be given to program');

Tried the first thing you said, aka put parameters in first string, leave second string empty, but it doesn't even play the song that way.

Tried the second, like this:
exec(getenv('comspec'),'/c mplayer.exe song.mp3 > NUL:');
Now the part that I don't understand is that under freepascal, it works correctly: it plays the song without displaying anything. But compuled with turbo pascal, it still shows what mplayer displays...
Anyway, I'll just compile it with freepascal. I hope it behaves ok in the program as well.
Thanks again.

Edit: Another noob question, no sense in opening a new thread for this:
Can I make it run in full screen mode directly, without having to press alt+enter when the program runs? Or modify the terminal window's size from within the program?
The highschool manuals just don't give enough info... :|

Guttorm 05-02-2007 06:23 AM

Hi again

I don't know how to set fullscreen within the program. But if you make a shortcut to the exe-file, you can right click it, select properties, and then in the "Options" tab, you can chose to run it in fullscreen.

Valkyrie_of_valhalla 05-02-2007 09:50 AM

Oh yeah, I forgot about that... I haven't booted into windows for quite a while now...
Thanks! :)


All times are GMT -5. The time now is 01:37 AM.