function send( pj )
%SEND Send output file to hardcopy device.
%   The output file is in the format specified by the device argument to 
%   the PRINT command. The command used to send the file to the output device 
%   is operating system specific. The command is stored in the PrintJob object.
%
%   Ex:
%      SEND( pj );
%
%   See also PRINT, PRINTOPT.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.6 $  $Date: 1998/09/18 20:09:18 $

lprcmd = pj.PrintCmd;

%Does something exist to send to the printer?
if ~exist( pj.FileName )
    error('No file to send to printer.')
end

if strcmp( computer, 'PCWIN' )
    cmd = sprintf(strrep(lprcmd,'\','\\'), pj.FileName);
    if pj.DebugMode
        disp( ['PRINT debugging: print command = ''' cmd '''.'] )
    end
    [s, r] = dos(pj,cmd);
    delete(pj.FileName);
    
else
    if strcmp( lprcmd, 'lp -c' ) 
        notBSD = 1;
    else
        notBSD = 0;
    end
    if ~isempty( pj.PrinterName )
        %If user specified a printer, add it to the printing command
        if isvms
            cmdOption = '/QUEUE=';
        else
            cmdOption = '-P';
        end
        lprcmd = [ lprcmd ' ' cmdOption pj.PrinterName ];
    end
    
    if pj.DebugMode
        disp( ['PRINT debugging: print command = ''' lprcmd ' ' pj.FileName '''.'] )
    end
    [s, r] = unix([lprcmd ' ' pj.FileName]);
    if notBSD
        % SGI and SOL2 without Berkley printing extensions do not
        % have a 'delete when done' option, so used copy option and
        % now delete the temporary file we made.
        delete(pj.FileName)
    end
end

if s & ~isempty(r)
    error( sprintf('Problem sending file to output device, system returned error :\n%s', r) )
end
