-
The CARAT binary gap> List([1..10], el -> CaratName(SpaceGroupIT(3,el)));
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
father: level 1 number of orbits 1 lengths 3
[ "min.6-1.1-0", "group.5-1.1-0", "min.7-1.1-0", "min.7-1.1-0", "min.7-1.2-0", "min.8-1.1-0", "min.8-1.1-0",
"min.8-1.2-0", "min.8-1.2-0", "group.6-1.1-0" ] I would like to not show the lines As said in the title the additional output goes to stderr: The GAP method InstallGlobalFunction( CaratCommandOStream, function( command, args, output )
local program, err;
# find executable
program := Filename( CARAT_BIN_DIR, command );
if program = fail then
Error( Concatenation( "Carat program ", command, " not found." ) );
fi;
# execute command
err := Process( DirectoryCurrent(), program, InputTextNone(),
output, CaratStringToWordList( args ) );
end );
InstallMethod( CaratName,
"with Carat program Name",
true, [ IsSpaceGroup ], 0,
function( grp )
local grpfile, resfile, gen, res, out, input, dim, mat, output;
dim := DimensionOfMatrixGroup( grp ) - 1;
if dim <> 2 and dim <> 3 then
Error( "sorry, only groups of dimension 2 and 3 are supported" );
fi;
if not IsRationalMatrixGroup( grp ) then
Error( "grp must be a rational matrix group" );
fi;
# Special case for p1 and P1
# binary Name segfaults
# https://github.com/lbfm-rwth/carat/issues/112
if IsTrivial(PointGroup(grp)) then
if dim = 2 then
return "min.2-1.1-0";
elif dim = 3 then
return "min.6-1.1-0";
fi;
fi;
# Get temporary file name
grpfile := CaratTmpFile( "grp" );
# Write Carat input to file; Carat binary "Name" does not read from stdin
# Group is expected to have as translation lattice Z^n (not centered unit cells) and
# act from the left in CARAT.
if IsAffineCrystGroupOnRight( grp ) then
gen := GeneratorsOfGroup( StandardAffineCrystGroup( TransposedMatrixGroup( grp ) ) );
else
gen := GeneratorsOfGroup( StandardAffineCrystGroup( grp ) );
fi;
CaratWriteMatrixFile( grpfile, gen );
# execute Carat program
res := "";
output := OutputTextString(res, true);
CaratCommandOStream( "Name", Concatenation( grpfile, " -c" ), output );;
CloseStream(output);
# remove temporary file
RemoveFile( grpfile );
return Chomp(res);
end ); The documentation of
Furthermore, using
Therefore, I assume shell redirection is also not possible with My GAP version:
So what can I do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
However, the But catching stdout directly without disc IO does not seem to be possible: InstallGlobalFunction( CaratExec, function( cmd, args, stdout_file, stderr_file )
local program;
# find executable
program := Filename( CARAT_BIN_DIR, cmd );
if program = fail then
Error( Concatenation( "Carat program ", cmd, " not found." ) );
fi;
# execute command
Exec( Concatenation(program, " ", args, " > ", stdout_file , " 2> ", stderr_file ) );
end );
InstallMethod( CaratName,
"with Carat program Name",
true, [ IsSpaceGroup ], 0,
function( grp )
local grpfile, resfile, gen, res, out, input, dim, mat, output;
dim := DimensionOfMatrixGroup( grp ) - 1;
if dim <> 2 and dim <> 3 then
Error( "sorry, only groups of dimension 2 and 3 are supported" );
fi;
if not IsRationalMatrixGroup( grp ) then
Error( "grp must be a rational matrix group" );
fi;
# Special case for p1 and P1
# binary Name segfaults
# https://github.com/lbfm-rwth/carat/issues/112
if IsTrivial(PointGroup(grp)) then
if dim = 2 then
return "min.2-1.1-0";
elif dim = 3 then
return "min.6-1.1-0";
fi;
fi;
# Get temporary file names
grpfile := CaratTmpFile( "grp" );
resfile := CaratTmpFile( "res" );
# Write Carat input to file; Carat binary "Name" does not read from stdin
# Group is expected to have as translation lattice Z^n (not centered unit cells) and
# act from the left in CARAT.
if IsAffineCrystGroupOnRight( grp ) then
gen := GeneratorsOfGroup( StandardAffineCrystGroup( TransposedMatrixGroup( grp ) ) );
else
gen := GeneratorsOfGroup( StandardAffineCrystGroup( grp ) );
fi;
CaratWriteMatrixFile( grpfile, gen );
# execute Carat program
CaratExec( "Name", Concatenation( grpfile, " -c" ), resfile, "/dev/null" );
# read Carat result from file, and remove temporary files
input := InputTextFile( resfile );
res := ReadLine( input );
CloseStream(input);
RemoveFile( grpfile );
RemoveFile( resfile );
return Chomp(res);
end ); |
Beta Was this translation helpful? Give feedback.
Unfortunately
Process
does not currently allow redirectingstderr
(see also issue #4657).You can however use a trick and instead of directly executing the target program, execute another program (such as a shell) which performs the redirection. This is indeed what some code does by using
Exec
, e.g. this:However,
Exec
is otherwise a bad tool, as it does not allow check exit codes (to see if the command actually worked) and if you want to hide or capture output, it must always go through temporary files). So in general I recommend not using it. Relatedly, PR #5103 adds an alternative "better" version ofExec
.Luckily
Exec