vips_system() now uses g_spawn_command_line_sync()
helps stop stray command windows appearing on Windows, better error msg too
This commit is contained in:
parent
7819fde047
commit
c81a12ee00
@ -26,6 +26,7 @@
|
|||||||
- added vips_foreign_load_buffer(), vips_foreign_save_buffer()
|
- added vips_foreign_load_buffer(), vips_foreign_save_buffer()
|
||||||
- added vips_object_set_from_string()
|
- added vips_object_set_from_string()
|
||||||
- support 1/2/4 bit palette tiff images with alpha
|
- support 1/2/4 bit palette tiff images with alpha
|
||||||
|
- vips_system() now uses g_spawn_command_line_sync()
|
||||||
|
|
||||||
6/3/14 started 7.38.6
|
6/3/14 started 7.38.6
|
||||||
- grey ramp minimum was wrong
|
- grey ramp minimum was wrong
|
||||||
|
5
TODO
5
TODO
@ -5,11 +5,6 @@
|
|||||||
|
|
||||||
deprecate this thing and stop ':' split
|
deprecate this thing and stop ':' split
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- support 1/2/4 bit palette tiff with alpha
|
|
||||||
|
|
||||||
- can we use postbuild elsewhere? look at use of "preclose" / "written", etc.
|
- can we use postbuild elsewhere? look at use of "preclose" / "written", etc.
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,6 +186,8 @@ gboolean vips_ispostfix( const char *a, const char *b );
|
|||||||
gboolean vips_isprefix( const char *a, const char *b );
|
gboolean vips_isprefix( const char *a, const char *b );
|
||||||
char *vips_break_token( char *str, const char *brk );
|
char *vips_break_token( char *str, const char *brk );
|
||||||
|
|
||||||
|
void vips__chomp( char *str );
|
||||||
|
|
||||||
int vips_vsnprintf( char *str, size_t size, const char *format, va_list ap );
|
int vips_vsnprintf( char *str, size_t size, const char *format, va_list ap );
|
||||||
int vips_snprintf( char *str, size_t size, const char *format, ... )
|
int vips_snprintf( char *str, size_t size, const char *format, ... )
|
||||||
__attribute__((format(printf, 3, 4)));
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
* 4/6/13
|
* 4/6/13
|
||||||
* - redo as a class
|
* - redo as a class
|
||||||
* - input and output images are now optional
|
* - input and output images are now optional
|
||||||
|
* 3/5/14
|
||||||
|
* - switch to g_spawn_command_line_sync() from popen() ... helps stop
|
||||||
|
* stray command-windows on Windows
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -119,8 +122,10 @@ vips_system_build( VipsObject *object )
|
|||||||
char line[VIPS_PATH_MAX];
|
char line[VIPS_PATH_MAX];
|
||||||
char txt[VIPS_PATH_MAX];
|
char txt[VIPS_PATH_MAX];
|
||||||
VipsBuf buf = VIPS_BUF_STATIC( txt );
|
VipsBuf buf = VIPS_BUF_STATIC( txt );
|
||||||
char *p;
|
char *std_output;
|
||||||
|
char *std_error;
|
||||||
int result;
|
int result;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
if( VIPS_OBJECT_CLASS( vips_system_parent_class )->build( object ) )
|
if( VIPS_OBJECT_CLASS( vips_system_parent_class )->build( object ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
@ -165,30 +170,48 @@ vips_system_build( VipsObject *object )
|
|||||||
cmd, VIPS_PATH_MAX, system->out_name ) )
|
cmd, VIPS_PATH_MAX, system->out_name ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
/* Swap all "%%" in the string for a single "%". We need this for
|
if( !g_spawn_command_line_sync( cmd,
|
||||||
* compatibility with older printf-based vips_system()s which
|
&std_output, &std_error, &result, &error ) ) {
|
||||||
* needed a double %%.
|
if( error ) {
|
||||||
*/
|
vips_error( class->nickname, "%s", error->message );
|
||||||
for( p = cmd; *p; p++ )
|
g_error_free( error );
|
||||||
if( p[0] == '%' &&
|
}
|
||||||
p[1] == '%' )
|
if( std_error ) {
|
||||||
memmove( p, p + 1, strlen( p ) );
|
vips__chomp( std_error );
|
||||||
|
if( strcmp( std_error, "" ) != 0 )
|
||||||
|
vips_error( class->nickname,
|
||||||
|
"error output: %s", std_error );
|
||||||
|
VIPS_FREE( std_error );
|
||||||
|
}
|
||||||
|
if( std_output ) {
|
||||||
|
vips__chomp( std_output );
|
||||||
|
if( strcmp( std_output, "" ) != 0 )
|
||||||
|
vips_error( class->nickname,
|
||||||
|
"output: %s", std_output );
|
||||||
|
VIPS_FREE( std_output );
|
||||||
|
}
|
||||||
|
vips_error_system( result, class->nickname,
|
||||||
|
"%s", _( "command failed" ) );
|
||||||
|
|
||||||
if( !(fp = vips_popenf( "%s", "r", cmd )) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
while( fgets( line, VIPS_PATH_MAX, fp ) )
|
|
||||||
if( !vips_buf_appends( &buf, line ) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
g_object_set( system, "log", vips_buf_all( &buf ), NULL );
|
|
||||||
|
|
||||||
if( (result = pclose( fp )) ) {
|
|
||||||
vips_error( class->nickname,
|
|
||||||
_( "command failed: \"%s\"" ), system->cmd_format );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_assert( !result );
|
||||||
|
|
||||||
|
if( std_error ) {
|
||||||
|
vips__chomp( std_error );
|
||||||
|
if( strcmp( std_error, "" ) != 0 )
|
||||||
|
vips_warn( class->nickname,
|
||||||
|
_( "stderr output: %s" ), std_error );
|
||||||
|
}
|
||||||
|
if( std_output ) {
|
||||||
|
vips__chomp( std_output );
|
||||||
|
g_object_set( system, "log", std_output, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
VIPS_FREE( std_output );
|
||||||
|
VIPS_FREE( std_error );
|
||||||
|
|
||||||
if( system->out_name ) {
|
if( system->out_name ) {
|
||||||
VipsImage *out;
|
VipsImage *out;
|
||||||
|
|
||||||
|
@ -1206,6 +1206,17 @@ vips_mkdirf( const char *name, ... )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Chop off any trailing whitespace.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
vips__chomp( char *str )
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
for( p = str + strlen( str ); p > str && isspace( p[-1] ); p-- )
|
||||||
|
p[-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/* Break a command-line argument into tokens separated by whitespace.
|
/* Break a command-line argument into tokens separated by whitespace.
|
||||||
*
|
*
|
||||||
* Strings can't be adjacent, so "hello world" (without quotes) is a single
|
* Strings can't be adjacent, so "hello world" (without quotes) is a single
|
||||||
|
Loading…
Reference in New Issue
Block a user