in reply to Re: Tk - system()
in thread Tk - system()

I am trying to create an input file from the GUI which is done by calling the OUTFILE filehandle. Then, I want to take this file and pass it to a .exe program which reads the title of the file and creates output files. This is where I call system() and try to output it to a specific directory. Before calling system, I had to specify the folder where the .exe file is if not, perl looks into the default directory and does nothing. I hope this helps. As for a better example, I wish I could give you one better but I'm having a hard time working it out.

Replies are listed 'Best First'.
Re^3: Tk - system()
by lil_v (Sexton) on Aug 06, 2008 at 18:23 UTC
    Here is something else I came up with after reading the docs you wrote:
    my $title = "something"; #title of the input file my $executable = "C:/Users/Desktop/file.exe"; # the .exe file where the input needs to be passed my $output = "C:/Users/Desktop"; # folder where the generated output files need to be located my $outfile = "C:/Users/Desktop/$title.in"; #location of the input file open(OUTFILE,">$outfile") or die "Can't open output file $outfile\ +n"; print OUTFILE @array; close OUTFILE; my $msg = $mw->messageBox(-icon => "info", -type => "OK", -title => 'Save', -message => "File was +successfully saved."); my @args = ("start",$executable,$title); for (@args) { # Apply smart-ish double quotes if (/ /) { $_ = qq{"$_"}; } }; chdir $output; #this command isn't working on Tk system(@args) == 0 or warn "Couldn't launch '$title' : $!/$?/$^E";
    This also works fine in perl but not in Tk. I think the problem here is that it doesn't locate the $output directory. I know that you chdir does nothing if the directory is not set properly. Is there another way of specifying the directory?
      Possibly the problem is you have double quotes ( which will interpolate on it's contents) around my $output = "C:/Users/Desktop";

      Try

      chdir 'C:/Users/Desktop' ; print pwd, "\n"; # see if it worked #or my $output = 'C:/Users/Desktop';
      notice the single quotes.

      If it still gives you trouble, specify everything as full paths in single quotes, until you get it to work without the chdir. You can always do a "print pwd\n" to see where you really are.

      my @args = ('start', 'C:/Users/Desktop/file.exe' , C:/Users/Desktop/something' );
      Once you get it to work with absolutes, work your way backwards and substitute the variables, and check pwd after any chdir attempt.

      I'm not really a human, but I play one on earth Remember How Lucky You Are
        thanks for your help, the output folder is a user input so I had to chomp that value before using it with chdir. It's fixed now, thanks again!