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

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?

Replies are listed 'Best First'.
Re^4: Tk - system()
by zentara (Cardinal) on Aug 06, 2008 at 19:46 UTC
    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!
        I have to tell you lil_v, that you have a bad habit of posting incomplete code examples, then finding a solution for something not shown in your code. In this case, your code shows nothing about "user input", yet it was chomping user input that was the culprit. Even the node title is misleading.

        I had to stare long and hard at your incomplete code example to even make an educated guess at what was wrong. From now on, if you do not post a complete working snippet that demonstrates your problem, I will likely skip over your node. Sorry.... but if you want to be lazy....so do I.


        I'm not really a human, but I play one on earth Remember How Lucky You Are